diff --git a/docs/zh/base/relations-query.md b/docs/zh/base/relations-query.md index 1ca332ee..5efdf2c4 100644 --- a/docs/zh/base/relations-query.md +++ b/docs/zh/base/relations-query.md @@ -230,9 +230,9 @@ public class Account implements Serializable { > 多对多注解 `@RelationManyToMany` 也是如此。 -**selfFieldSplitBy 分割查询** +**selfValueSplitBy 分割查询** -若 `selfField` 是一个 `由字符拼接而成的列表(如 1,2,3)`,那么,我们可以通过配置 `selfFieldSplitBy` 来指定使用 `selfField` 的值根据字符切割后查询, +若 `selfField` 的值是一个 `由字符拼接而成的列表(如: "1,2,3" )`,那么,我们可以通过配置 `selfValueSplitBy` 来指定使用 `selfField` 的值根据字符切割后查询, 如下代码所示: ```java 8 @@ -263,7 +263,7 @@ public class PatientVO1 implements Serializable { @RelationOneToMany( selfField = "diseaseIds", - selfFieldSplitBy = ",", //使用 , 进行分割 + selfValueSplitBy = ",", //使用 "," 对 diseaseIds 的值进行分割 targetTable = "tb_disease", //只获取某个字段值需要填入目标表名 targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换 valueField = "name" //测试只获取某个字段值是否正常 @@ -272,14 +272,14 @@ public class PatientVO1 implements Serializable { @RelationOneToMany( selfField = "tagIds", - selfFieldSplitBy = "/", //使用 / 进行分割 + selfValueSplitBy = "/", //使用 "/" 对 tagIds 的值进行分割 targetField = "tagId" //测试目标字段是数字类型是否正常转换 ) private List tagList; @RelationOneToMany( selfField = "diseaseIds", - selfFieldSplitBy = ",", //使用 , 进行分割 + selfValueSplitBy = ",", //使用 "," 对 diseaseIds 的值进行分割 targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换 mapKeyField = "diseaseId" //测试Map映射 ) @@ -291,7 +291,8 @@ public class PatientVO1 implements Serializable { 进行查询 ```java -PatientVO1 patientVO1 = patientMapper.selectOneWithRelationsByQueryAs(QueryWrapper.create().orderBy(PatientVO1::getPatientId, false).limit(1), PatientVO1.class); +QueryWrapper qw = QueryWrapper.create().orderBy(PatientVO1::getPatientId, false).limit(1) +PatientVO1 patientVO1 = patientMapper.selectOneWithRelationsByQueryAs(qw, PatientVO1.class); System.out.println(JSON.toJSONString(patientVO1)); ``` diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/RelationOneToMany.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/RelationOneToMany.java index 969ec353..fae4a753 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/RelationOneToMany.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/RelationOneToMany.java @@ -38,7 +38,7 @@ public @interface RelationOneToMany { * 当前字段值根据字符串分割 * @return 分割字符串 */ - String selfFieldSplitBy() default ""; + String selfValueSplitBy() default ""; /** *

diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToMany.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToMany.java index 162c9caf..09f8d012 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToMany.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToMany.java @@ -35,7 +35,7 @@ class OneToMany extends ToManyRelation { , annotation.extraCondition() , annotation.selectColumns()); - this.selfFieldSplitBy = annotation.selfFieldSplitBy(); + this.selfValueSplitBy = annotation.selfValueSplitBy(); this.orderBy = annotation.orderBy(); this.limit = annotation.limit(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java index d8e643bb..54840098 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java @@ -29,7 +29,7 @@ class ToManyRelation extends AbstractRelation { protected FieldWrapper mapKeyFieldWrapper; protected String orderBy; protected long limit = 0; - protected String selfFieldSplitBy; + protected String selfValueSplitBy; public ToManyRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField, @@ -51,7 +51,7 @@ class ToManyRelation extends AbstractRelation { */ @Override public QueryWrapper buildQueryWrapper(Set targetValues) { - if (StringUtil.isNotBlank(selfFieldSplitBy) && CollectionUtil.isNotEmpty(targetValues)) { + if (StringUtil.isNotBlank(selfValueSplitBy) && CollectionUtil.isNotEmpty(targetValues)) { Set newTargetValues = new HashSet<>(); for (Object targetValue : targetValues) { if (targetValue == null) { @@ -60,7 +60,7 @@ class ToManyRelation extends AbstractRelation { if (!(targetValue instanceof String)) { throw FlexExceptions.wrap("split field only support String type, but current type is: \"" + targetValue.getClass().getName() + "\""); } - String[] splitValues = ((String) targetValue).split(selfFieldSplitBy); + String[] splitValues = ((String) targetValue).split(selfValueSplitBy); for (String splitValue : splitValues) { //优化分割后的数据类型(防止在数据库查询时候出现隐式转换) newTargetValues.add(ConvertUtil.convert(splitValue, targetFieldWrapper.getFieldType())); @@ -101,8 +101,8 @@ class ToManyRelation extends AbstractRelation { } } } else { - if (StringUtil.isNotBlank(selfFieldSplitBy)) { - String[] splitValues = ((String) selfValue).split(selfFieldSplitBy); + if (StringUtil.isNotBlank(selfValueSplitBy)) { + String[] splitValues = ((String) selfValue).split(selfValueSplitBy); targetMappingValues.addAll(Arrays.asList(splitValues)); } else { targetMappingValues.add((String) selfValue); diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/PatientVO1.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/PatientVO1.java index 9df178d5..3de34d72 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/PatientVO1.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/PatientVO1.java @@ -41,7 +41,7 @@ public class PatientVO1 implements Serializable { @RelationOneToMany( selfField = "diseaseIds", - selfFieldSplitBy = ",", //使用 , 进行分割 + selfValueSplitBy = ",", //使用 , 进行分割 targetTable = "tb_disease", //只获取某个字段值需要填入目标表名 targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换 valueField = "name" //测试只获取某个字段值是否正常 @@ -50,14 +50,14 @@ public class PatientVO1 implements Serializable { @RelationOneToMany( selfField = "tagIds", - selfFieldSplitBy = "/", //使用 / 进行分割 + selfValueSplitBy = "/", //使用 / 进行分割 targetField = "tagId" //测试目标字段是数字类型是否正常转换 ) private List tagList; @RelationOneToMany( selfField = "diseaseIds", - selfFieldSplitBy = ",", //使用 , 进行分割 + selfValueSplitBy = ",", //使用 , 进行分割 targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换 mapKeyField = "diseaseId" //测试Map映射 )