SELECT * FROM t_user WHERE
id IN (
SELECT user_id FROM a_user_and_role WHERE role_id IN (
SELECT id FROM t_role WHERE ...
)
)
示例
表 t_menu 有一个列 parent_id,它将 id 列本身引用为外键。parent_id 列用于定义菜单项之间的层次父子关系。菜单通过通用 RBAC 模型作为系统资源分配给用户。那么菜单到用户的实体路径即为:menu,perm,role,user,用于生成嵌套查询语句。
嵌套查询
DoytoQuery通过解析字段上配置的@DomainPath注解来为字段生成嵌套查询语句。
注解定义如下:
DomainPath.java
@Target(FIELD)
@Retention(RUNTIME)
public @interface DomainPath {
/**
* To describe how to route from the host domain to the target domain.
*
* @return paths array
*/
String[] value();
String localAlias() default "t";
/**
* The field in this domain to maintain the relationship with the target domain.
*
* @return name of the local field
*/
String localField() default "id";
/**
* The field in another domain to maintain the relationship with this domain.
*
* @return name of the foreign field
*/
String foreignField() default "id";
String foreignAlias() default "t1";
}