From d708d474aaa11f5062c4b71040123546aba28b13 Mon Sep 17 00:00:00 2001 From: mazhicheng Date: Sat, 1 Jun 2019 13:31:36 +0800 Subject: [PATCH] =?UTF-8?q?Binder.bind()=E5=AE=9E=E7=8E=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/core/binding/EntityBinder.java | 71 ++++------- .../diboot/core/binding/EntityListBinder.java | 113 ++++++++---------- .../com/diboot/core/binding/FieldBinder.java | 102 ++++++---------- .../core/binding/parser/MiddleTable.java | 40 ++++++- .../com/diboot/core/util/SqlExecutor.java | 33 ++++- .../com/diboot/example/vo/DepartmentVO.java | 6 +- .../java/com/diboot/example/vo/UserVO.java | 15 ++- 7 files changed, 189 insertions(+), 191 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/EntityBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/EntityBinder.java index 7fd908c..b40f1fb 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/EntityBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/EntityBinder.java @@ -72,24 +72,33 @@ public class EntityBinder extends BaseBinder { if(V.isEmpty(annoObjectForeignKeyList)){ return; } + // 结果转换Map + Map valueEntityMap = new HashMap<>(); // 通过中间表关联Entity // @BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id AND department.deleted=0") // Organization organization; if(middleTable != null){ - // 提取中间表查询SQL: SELECT id, org_id FROM department WHERE id IN(?) - String sql = middleTable.toSQL(annoObjectForeignKeyList); - // 执行查询并合并结果 - String keyName = middleTable.getEqualsToRefEntityPkColumn(), valueName = middleTable.getEqualsToAnnoObjectFKColumn(); - Map middleTableResultMap = SqlExecutor.executeQueryAndMergeResult(sql, annoObjectForeignKeyList, keyName, valueName); + Map middleTableResultMap = middleTable.executeOneToOneQuery(annoObjectForeignKeyList); if(V.notEmpty(middleTableResultMap)){ // 提取entity主键值集合 - Collection middleTableColumnValueList = middleTableResultMap.keySet(); + Collection middleTableColumnValueList = middleTableResultMap.values(); // 构建查询条件 queryWrapper.in(S.toSnakeCase(referencedEntityPrimaryKey), middleTableColumnValueList); // 查询entity列表 List list = referencedService.getEntityList(queryWrapper); - // 基于中间表查询结果和entity列表绑定结果 - bindingResultWithMiddleTable(S.toLowerCaseCamel(referencedEntityPrimaryKey), list, middleTableResultMap); + if(V.notEmpty(list)){ + // 转换entity列表为Map + Map listMap = BeanUtils.convertToStringKeyObjectMap(list, S.toLowerCaseCamel(referencedEntityPrimaryKey)); + for(Map.Entry entry : middleTableResultMap.entrySet()){ + Object fetchValueId = entry.getValue(); + if(fetchValueId == null){ + continue; + } + String key = entry.getKey(); + T value = listMap.get(String.valueOf(fetchValueId)); + valueEntityMap.put(key, value); + } + } } } // 直接关联Entity @@ -100,47 +109,15 @@ public class EntityBinder extends BaseBinder { queryWrapper.in(S.toSnakeCase(referencedEntityPrimaryKey), annoObjectForeignKeyList); // 查询entity列表 List list = referencedService.getEntityList(queryWrapper); - // 绑定结果 - bindingResult(S.toLowerCaseCamel(referencedEntityPrimaryKey), list); - } - } - - /*** - * 基于中间表查询结果和entity列表绑定结果 - * @param doPkPropName - * @param list - */ - private void bindingResultWithMiddleTable(String doPkPropName, List list, Map middleTableResultMap) { - // 构建IdString-Entity之间的映射Map - Map valueEntityMap = new HashMap<>(list.size()); - for(E entity : list){ - // 获取主键值 - String pkValue = BeanUtils.getStringProperty(entity, doPkPropName); - // 得到对应Entity - List annoObjFKList = middleTableResultMap.get(pkValue); - if(V.notEmpty(annoObjFKList)){ - valueEntityMap.put(String.valueOf(annoObjFKList.get(0)), entity); - } - else{ - log.warn("{}.{}={} 无匹配结果!", entity.getClass().getSimpleName(), doPkPropName, pkValue); + if(V.notEmpty(list)){ + String refEntityPKFieldName = S.toLowerCaseCamel(referencedEntityPrimaryKey); + for(T entity : list){ + String pkValue = BeanUtils.getStringProperty(entity, refEntityPKFieldName); + valueEntityMap.put(pkValue, entity); + } } } - // 绑定 - BeanUtils.bindPropValueOfList(annoObjectField, annoObjectList, annoObjectForeignKey, valueEntityMap); - } - - /*** - * 绑定结果 - * @param doPkPropName - * @param list - */ - private void bindingResult(String doPkPropName, List list) { - Map valueEntityMap = new HashMap<>(list.size()); - for(T entity : list){ - String pkValue = BeanUtils.getStringProperty(entity, doPkPropName); - valueEntityMap.put(pkValue, entity); - } - // 绑定 + // 绑定结果 BeanUtils.bindPropValueOfList(annoObjectField, annoObjectList, annoObjectForeignKey, valueEntityMap); } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/EntityListBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/EntityListBinder.java index f06e18e..4dcc30c 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/EntityListBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/EntityListBinder.java @@ -45,32 +45,35 @@ public class EntityListBinder extends EntityBinder { if(V.isEmpty(annoObjectForeignKeyList)){ return; } + Map> valueEntityListMap = new HashMap<>(); // 解析中间表查询 1-N关联,如: //User.class @BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id") if(middleTable != null){ - // 构建查询SQL: SELECT user_id, role_id FROM user_role WHERE user_id IN (?) - String sql = middleTable.toSQL(annoObjectForeignKeyList); - // 执行查询并合并结果 - String valueName = middleTable.getEqualsToRefEntityPkColumn(), keyName = middleTable.getEqualsToAnnoObjectFKColumn(); - Map middleTableResultMap = SqlExecutor.executeQueryAndMergeResult(sql, annoObjectForeignKeyList, keyName, valueName); + Map middleTableResultMap = middleTable.executeOneToManyQuery(annoObjectForeignKeyList); if(V.notEmpty(middleTableResultMap)){ // 收集查询结果values集合 - List entityIdList = new ArrayList(); - for(Map.Entry entry : middleTableResultMap.entrySet()){ - if(V.notEmpty(entry.getValue())){ - for(Object id : entry.getValue()){ - if(!entityIdList.contains(id)){ - entityIdList.add(id); - } - } - } - } + List entityIdList = extractIdValueFromMap(middleTableResultMap); // 构建查询条件 queryWrapper.in(S.toSnakeCase(referencedEntityPrimaryKey), entityIdList); // 查询entity列表: List List list = referencedService.getEntityList(queryWrapper); - // 绑定结果 - bindingResultWithMiddleTable(S.toLowerCaseCamel(annoObjectForeignKey), list, middleTableResultMap); + // 转换entity列表为Map + Map entityMap = BeanUtils.convertToStringKeyObjectMap(list, S.toLowerCaseCamel(referencedEntityPrimaryKey)); + for(Map.Entry entry : middleTableResultMap.entrySet()){ + // List + List annoObjFKList = entry.getValue(); + if(V.isEmpty(annoObjFKList)){ + continue; + } + List valueList = new ArrayList(); + for(Object obj : annoObjFKList){ + T ent = entityMap.get(String.valueOf(obj)); + if(ent != null){ + valueList.add(ent); + } + } + valueEntityListMap.put(entry.getKey(), valueList); + } } } else{ @@ -78,58 +81,40 @@ public class EntityListBinder extends EntityBinder { queryWrapper.in(S.toSnakeCase(referencedEntityPrimaryKey), annoObjectForeignKeyList); // 查询entity列表 List list = referencedService.getEntityList(queryWrapper); - // 绑定结果 - bindingResult(S.toLowerCaseCamel(referencedEntityPrimaryKey), list); - } - } - - /*** - * 基于中间表查询结果和entity列表绑定结果 - * @param annoObjectForeignKey - * @param list - */ - private void bindingResultWithMiddleTable(String annoObjectForeignKey, List list, Map middleTableResultMap) { - if(V.isEmpty(list)){ - return; - } - // 将 List 转换为 Map - Map entityMap = BeanUtils.convertToStringKeyObjectMap(list, annoObjectForeignKey); - // 将Map> 转换为 Map> - Map> valueEntityMap = new HashMap<>(list.size()); - for(Map.Entry entry : middleTableResultMap.entrySet()){ - // List - List annoObjFKList = entry.getValue(); - if(V.notEmpty(annoObjFKList)){ - List valueList = new ArrayList(); - for(Object obj : annoObjFKList){ - E ent = entityMap.get(String.valueOf(obj)); - if(ent != null){ - valueList.add(ent); + if(V.notEmpty(list)){ + for(T entity : list){ + String keyValue = BeanUtils.getStringProperty(entity, S.toLowerCaseCamel(referencedEntityPrimaryKey)); + List entityList = valueEntityListMap.get(keyValue); + if(entityList == null){ + entityList = new ArrayList<>(); + valueEntityListMap.put(keyValue, entityList); } + entityList.add(entity); } - valueEntityMap.put(entry.getKey(), valueList); - } - else{ - log.warn("转换结果异常,中间关联条件数据不一致"); } } - // 绑定 - BeanUtils.bindPropValueOfList(annoObjectField, annoObjectList, annoObjectForeignKey, valueEntityMap); - } - - private void bindingResult(String fkName, List list) { - Map> valueEntityListMap = new HashMap<>(list.size()); - for(T entity : list){ - String keyValue = BeanUtils.getStringProperty(entity, fkName); - List entityList = valueEntityListMap.get(keyValue); - if(entityList == null){ - entityList = new ArrayList<>(); - valueEntityListMap.put(keyValue, entityList); - } - entityList.add(entity); - } - // 绑定 + // 绑定结果 BeanUtils.bindPropValueOfList(annoObjectField, annoObjectList, annoObjectForeignKey, valueEntityListMap); } + /** + * 从Map中提取ID的值 + * @param middleTableResultMap + * @return + */ + private List extractIdValueFromMap(Map middleTableResultMap) { + List entityIdList = new ArrayList(); + for(Map.Entry entry : middleTableResultMap.entrySet()){ + if(V.isEmpty(entry.getValue())){ + continue; + } + for(Object id : entry.getValue()){ + if(!entityIdList.contains(id)){ + entityIdList.add(id); + } + } + } + return entityIdList; + } + } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/FieldBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/FieldBinder.java index aa404dc..70b97c6 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/FieldBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/FieldBinder.java @@ -85,60 +85,23 @@ public class FieldBinder extends BaseBinder { if(V.isEmpty(annoObjectForeignKeyList)){ return; } + // 将结果list转换成map + Map middleTableResultMap = null; //@BindField(entity = Organization.class, field="name", condition="this.department_id=department.id AND department.org_id=id") //String orgName; if(middleTable != null){ - // 提取中间表查询SQL: SELECT id, org_id FROM department WHERE id IN(?) - String sql = middleTable.toSQL(annoObjectForeignKeyList); - // 执行查询并合并结果 - String keyName = middleTable.getEqualsToAnnoObjectFKColumn(), valueName = middleTable.getEqualsToRefEntityPkColumn(); - Map middleTableResultMap = SqlExecutor.executeQueryAndMergeResult(sql, annoObjectForeignKeyList, keyName, valueName); + middleTableResultMap = middleTable.executeOneToOneQuery(annoObjectForeignKeyList); if(V.notEmpty(middleTableResultMap)){ // 收集查询结果values集合 - List middleTableColumnValueList = new ArrayList(); - for(Map.Entry entry : middleTableResultMap.entrySet()){ - if(V.notEmpty(entry.getValue())){ - for(Object id : entry.getValue()){ - if(!middleTableColumnValueList.contains(id)){ - middleTableColumnValueList.add(id); - } - } - } - } + Collection middleTableColumnValueList = middleTableResultMap.values(); // 构建查询条件 List selectColumns = new ArrayList<>(referencedGetterColumnNameList.size()+1); selectColumns.add(referencedEntityPkName); selectColumns.addAll(referencedGetterColumnNameList); queryWrapper.select(S.toStringArray(selectColumns)).in(S.toSnakeCase(referencedEntityPrimaryKey), middleTableColumnValueList); - // 获取匹配结果的mapList: SELECT id,name FROM organization - List> mapList = referencedService.getMapList(queryWrapper); - if(V.isEmpty(mapList)){ - return; - } - // 将结果list转换成map - Map> referencedEntityPk2DataMap = new HashMap<>(mapList.size()); - // 转换列名为字段名(MyBatis-plus的getMapList结果会将列名转成驼峰式) - String referencedEntityPkFieldName = S.toLowerCaseCamel(referencedEntityPkName); - for(Map map : mapList){ - Object pkVal = map.get(referencedEntityPkFieldName); - if(pkVal != null){ - referencedEntityPk2DataMap.put(String.valueOf(pkVal), map); - } - } - // 遍历list并赋值 - for(Object annoObject : annoObjectList){ - // 将数字类型转换成字符串,以便解决类型不一致的问题 - String annoObjectId = BeanUtils.getStringProperty(annoObject, annoObjectFkFieldName); - // 通过中间结果Map转换得到OrgId - List valueList = middleTableResultMap.get(annoObjectId); - String annoObjectFkFieldValue = String.valueOf(valueList.get(0)); - Map relationMap = referencedEntityPk2DataMap.get(annoObjectFkFieldValue); - if(relationMap != null){ - for(int i = 0; i< annoObjectSetterPropNameList.size(); i++){ - BeanUtils.setProperty(annoObject, annoObjectSetterPropNameList.get(i), relationMap.get(S.toLowerCaseCamel(referencedGetterColumnNameList.get(i)))); - } - } - } + } + else{ + return; } } else{ @@ -147,33 +110,40 @@ public class FieldBinder extends BaseBinder { selectColumns.add(referencedEntityPkName); selectColumns.addAll(referencedGetterColumnNameList); queryWrapper.select(S.toStringArray(selectColumns)).in(referencedEntityPkName, annoObjectForeignKeyList); - // 获取匹配结果的mapList - List> mapList = referencedService.getMapList(queryWrapper); - if(V.isEmpty(mapList)){ - return; + } + + // 获取匹配结果的mapList + List> mapList = referencedService.getMapList(queryWrapper); + if(V.isEmpty(mapList)){ + return; + } + // 将结果list转换成map + Map> referencedEntityPk2DataMap = new HashMap<>(mapList.size()); + // 转换列名为字段名(MyBatis-plus的getMapList结果会将列名转成驼峰式) + String referencedEntityPkFieldName = S.toLowerCaseCamel(referencedEntityPkName); + for(Map map : mapList){ + Object pkVal = map.get(referencedEntityPkFieldName); + if(pkVal != null){ + referencedEntityPk2DataMap.put(String.valueOf(pkVal), map); } - // 将结果list转换成map - Map> referencedEntityPk2DataMap = new HashMap<>(mapList.size()); - // 转换列名为字段名(MyBatis-plus的getMapList结果会将列名转成驼峰式) - String referencedEntityPkFieldName = S.toLowerCaseCamel(referencedEntityPkName); - for(Map map : mapList){ - Object pkVal = map.get(referencedEntityPkFieldName); - if(pkVal != null){ - referencedEntityPk2DataMap.put(String.valueOf(pkVal), map); - } + } + // 遍历list并赋值 + for(Object annoObject : annoObjectList){ + // 将数字类型转换成字符串,以便解决类型不一致的问题 + String annoObjectId = BeanUtils.getStringProperty(annoObject, annoObjectFkFieldName); + // 通过中间结果Map转换得到OrgId + if(V.notEmpty(middleTableResultMap)){ + Object value = middleTableResultMap.get(annoObjectId); + annoObjectId = String.valueOf(value); } - // 遍历list并赋值 - for(Object annoObject : annoObjectList){ - // 将数字类型转换成字符串,以便解决类型不一致的问题 - String annoObjectId = BeanUtils.getStringProperty(annoObject, annoObjectFkFieldName); - Map relationMap = referencedEntityPk2DataMap.get(annoObjectId); - if(relationMap != null){ - for(int i = 0; i< annoObjectSetterPropNameList.size(); i++){ - BeanUtils.setProperty(annoObject, annoObjectSetterPropNameList.get(i), relationMap.get(S.toLowerCaseCamel(referencedGetterColumnNameList.get(i)))); - } + Map relationMap = referencedEntityPk2DataMap.get(annoObjectId); + if(relationMap != null){ + for(int i = 0; i< annoObjectSetterPropNameList.size(); i++){ + BeanUtils.setProperty(annoObject, annoObjectSetterPropNameList.get(i), relationMap.get(S.toLowerCaseCamel(referencedGetterColumnNameList.get(i)))); } } } + } } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/MiddleTable.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/MiddleTable.java index 854c80b..7039b2e 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/MiddleTable.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/MiddleTable.java @@ -2,11 +2,13 @@ package com.diboot.core.binding.parser; import com.diboot.core.config.Cons; import com.diboot.core.util.S; +import com.diboot.core.util.SqlExecutor; import com.diboot.core.util.V; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 中间表 @@ -68,6 +70,40 @@ public class MiddleTable { return equalsToRefEntityPkColumn; } + /** + * 执行1-1关联查询,得到关联映射Map + * @param annoObjectForeignKeyList + * @return + */ + public Map executeOneToOneQuery(List annoObjectForeignKeyList){ + // 提取中间表查询SQL: SELECT id, org_id FROM department WHERE id IN(?) + String sql = toSQL(annoObjectForeignKeyList); + // 执行查询并合并结果 + //id + String keyName = getEqualsToAnnoObjectFKColumn(), + //org_id + valueName = getEqualsToRefEntityPkColumn(); + Map middleTableResultMap = SqlExecutor.executeQueryAndMergeOneToOneResult(sql, annoObjectForeignKeyList, keyName, valueName); + return middleTableResultMap; + } + + /** + * 执行1-N关联查询,得到关联映射Map + * @param annoObjectForeignKeyList + * @return + */ + public Map executeOneToManyQuery(List annoObjectForeignKeyList){ + // 提取中间表查询SQL: SELECT user_id, role_id FROM user_role WHERE user_id IN(?) + String sql = toSQL(annoObjectForeignKeyList); + // 执行查询并合并结果 + //user_id + String keyName = getEqualsToAnnoObjectFKColumn(), + //role_id + valueName = getEqualsToRefEntityPkColumn(); + Map middleTableResultMap = SqlExecutor.executeQueryAndMergeOneToManyResult(sql, annoObjectForeignKeyList, keyName, valueName); + return middleTableResultMap; + } + /** * 转换查询SQL * @param annoObjectForeignKeyList 注解外键值的列表,用于拼接SQL查询 @@ -80,8 +116,8 @@ public class MiddleTable { // 构建SQL StringBuilder sb = new StringBuilder(); sb.append("SELECT ").append(this.equalsToAnnoObjectFKColumn).append(Cons.SEPARATOR_COMMA) - .append(this.equalsToRefEntityPkColumn).append(" FROM ").append(this.table) - .append(" WHERE ").append(this.equalsToAnnoObjectFKColumn).append(" IN ("); + .append(this.equalsToRefEntityPkColumn).append(" FROM ").append(this.table) + .append(" WHERE ").append(this.equalsToAnnoObjectFKColumn).append(" IN ("); String params = S.repeat("?", ",", annoObjectForeignKeyList.size()); sb.append(params).append(")"); if(this.additionalConditions != null){ diff --git a/diboot-core/src/main/java/com/diboot/core/util/SqlExecutor.java b/diboot-core/src/main/java/com/diboot/core/util/SqlExecutor.java index 8b062b1..7e9f9bf 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/SqlExecutor.java +++ b/diboot-core/src/main/java/com/diboot/core/util/SqlExecutor.java @@ -39,7 +39,7 @@ public class SqlExecutor { log.warn("查询参数集合数量过多, size={},请检查调用是否合理!", params.size()); } } - log.debug("执行查询SQL: "+sql); + log.debug("==>\tSQL: "+sql); try(SqlSession session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)){ if(V.notEmpty(params)){ for(int i=0; i Map executeQueryAndMergeOneToOneResult(String sql, List params, String keyName, String valueName) { + List> resultSetMapList = null; + try { + resultSetMapList = executeQuery(sql, params); + } catch (Exception e) { + log.warn("执行查询异常", e); + } + // 合并list为map + Map resultMap = new HashMap<>(); + if(V.notEmpty(resultSetMapList)){ + for(Map row : resultSetMapList){ + String key = String.valueOf(row.get(keyName)); + Object value = row.get(valueName); + resultMap.put(key, value); + } + } + return resultMap; + } + /** * 执行查询和合并结果并将结果Map的key类型转成String * @@ -76,7 +103,7 @@ public class SqlExecutor { * @param params * @return */ - public static Map executeQueryAndMergeResult(String sql, List params, String keyName, String valueName){ + public static Map executeQueryAndMergeOneToManyResult(String sql, List params, String keyName, String valueName){ List> resultSetMapList = null; try { resultSetMapList = executeQuery(sql, params); diff --git a/diboot-example/src/main/java/com/diboot/example/vo/DepartmentVO.java b/diboot-example/src/main/java/com/diboot/example/vo/DepartmentVO.java index fcb8286..ed6da9c 100644 --- a/diboot-example/src/main/java/com/diboot/example/vo/DepartmentVO.java +++ b/diboot-example/src/main/java/com/diboot/example/vo/DepartmentVO.java @@ -18,15 +18,15 @@ import java.util.List; public class DepartmentVO extends Department { private static final long serialVersionUID = -362116388664907913L; + // 直接关联Entity中的某字段 @BindField(entity = Organization.class, field = "name", condition = "org_id=id") private String orgName; + // 直接关联Entity @BindEntity(entity = Organization.class, condition="this.org_id=id") private Organization organization; - @BindField(entity = Department.class, field = "name", condition = "parent_id=id") - private String parentName; - + // 直接关联多个Entity @BindEntityList(entity = Department.class, condition = "id=parent_id") private List children; diff --git a/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java b/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java index d82475f..110bc45 100644 --- a/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java +++ b/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java @@ -21,24 +21,27 @@ import java.util.List; public class UserVO extends User { private static final long serialVersionUID = 3526115343377985725L; + // 绑定元数据枚举 @BindMetadata(type="GENDER", field = "gender") private String genderLabel; + // 字段关联,相同条件的entity+condition将合并为一条SQL查询 @BindField(entity=Department.class, field="name", condition="department_id=id AND code IS NOT NULL") private String deptName; + @BindField(entity=Department.class, field="code", condition="department_id=id") + private String deptCode; - @BindEntity(entity = Department.class, condition="department_id=id") - private Department department; - - // 支持级联字段关联 + // 支持级联字段关联,相同条件的entity+condition将合并为一条SQL查询 @BindField(entity = Organization.class, field="name", condition="this.department_id=department.id AND department.org_id=id") private String orgName; + @BindField(entity = Organization.class, field="telphone", condition="this.department_id=department.id AND department.org_id=id") + private String orgTelphone; - // 通过中间表关联 + // 通过中间表关联Entity @BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id") // AND deleted=0 private Organization organization; - // 支持多-多Entity实体关联 + // 支持通过中间表的多-多Entity实体关联 @BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id") private List roleList;