mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
refactor: rename "selfFieldSplitBy" to "selfValueSplitBy"
This commit is contained in:
parent
82e0f97c55
commit
9a7af005df
@ -230,9 +230,9 @@ public class Account implements Serializable {
|
|||||||
|
|
||||||
> 多对多注解 `@RelationManyToMany` 也是如此。
|
> 多对多注解 `@RelationManyToMany` 也是如此。
|
||||||
|
|
||||||
**selfFieldSplitBy 分割查询** <Badge type="tip" text="v1.6.8" />
|
**selfValueSplitBy 分割查询** <Badge type="tip" text="^ v1.6.8" />
|
||||||
|
|
||||||
若 `selfField` 是一个 `由字符拼接而成的列表(如 1,2,3)`,那么,我们可以通过配置 `selfFieldSplitBy` 来指定使用 `selfField` 的值根据字符切割后查询,
|
若 `selfField` 的值是一个 `由字符拼接而成的列表(如: "1,2,3" )`,那么,我们可以通过配置 `selfValueSplitBy` 来指定使用 `selfField` 的值根据字符切割后查询,
|
||||||
如下代码所示:
|
如下代码所示:
|
||||||
|
|
||||||
```java 8
|
```java 8
|
||||||
@ -263,7 +263,7 @@ public class PatientVO1 implements Serializable {
|
|||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "diseaseIds",
|
selfField = "diseaseIds",
|
||||||
selfFieldSplitBy = ",", //使用 , 进行分割
|
selfValueSplitBy = ",", //使用 "," 对 diseaseIds 的值进行分割
|
||||||
targetTable = "tb_disease", //只获取某个字段值需要填入目标表名
|
targetTable = "tb_disease", //只获取某个字段值需要填入目标表名
|
||||||
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
||||||
valueField = "name" //测试只获取某个字段值是否正常
|
valueField = "name" //测试只获取某个字段值是否正常
|
||||||
@ -272,14 +272,14 @@ public class PatientVO1 implements Serializable {
|
|||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "tagIds",
|
selfField = "tagIds",
|
||||||
selfFieldSplitBy = "/", //使用 / 进行分割
|
selfValueSplitBy = "/", //使用 "/" 对 tagIds 的值进行分割
|
||||||
targetField = "tagId" //测试目标字段是数字类型是否正常转换
|
targetField = "tagId" //测试目标字段是数字类型是否正常转换
|
||||||
)
|
)
|
||||||
private List<Tag> tagList;
|
private List<Tag> tagList;
|
||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "diseaseIds",
|
selfField = "diseaseIds",
|
||||||
selfFieldSplitBy = ",", //使用 , 进行分割
|
selfValueSplitBy = ",", //使用 "," 对 diseaseIds 的值进行分割
|
||||||
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
||||||
mapKeyField = "diseaseId" //测试Map映射
|
mapKeyField = "diseaseId" //测试Map映射
|
||||||
)
|
)
|
||||||
@ -291,7 +291,8 @@ public class PatientVO1 implements Serializable {
|
|||||||
|
|
||||||
进行查询
|
进行查询
|
||||||
```java
|
```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));
|
System.out.println(JSON.toJSONString(patientVO1));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public @interface RelationOneToMany {
|
|||||||
* 当前字段值根据字符串分割
|
* 当前字段值根据字符串分割
|
||||||
* @return 分割字符串
|
* @return 分割字符串
|
||||||
*/
|
*/
|
||||||
String selfFieldSplitBy() default "";
|
String selfValueSplitBy() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class OneToMany<SelfEntity> extends ToManyRelation<SelfEntity> {
|
|||||||
, annotation.extraCondition()
|
, annotation.extraCondition()
|
||||||
, annotation.selectColumns());
|
, annotation.selectColumns());
|
||||||
|
|
||||||
this.selfFieldSplitBy = annotation.selfFieldSplitBy();
|
this.selfValueSplitBy = annotation.selfValueSplitBy();
|
||||||
this.orderBy = annotation.orderBy();
|
this.orderBy = annotation.orderBy();
|
||||||
this.limit = annotation.limit();
|
this.limit = annotation.limit();
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
protected FieldWrapper mapKeyFieldWrapper;
|
protected FieldWrapper mapKeyFieldWrapper;
|
||||||
protected String orderBy;
|
protected String orderBy;
|
||||||
protected long limit = 0;
|
protected long limit = 0;
|
||||||
protected String selfFieldSplitBy;
|
protected String selfValueSplitBy;
|
||||||
|
|
||||||
|
|
||||||
public ToManyRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField,
|
public ToManyRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField,
|
||||||
@ -51,7 +51,7 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public QueryWrapper buildQueryWrapper(Set<Object> targetValues) {
|
public QueryWrapper buildQueryWrapper(Set<Object> targetValues) {
|
||||||
if (StringUtil.isNotBlank(selfFieldSplitBy) && CollectionUtil.isNotEmpty(targetValues)) {
|
if (StringUtil.isNotBlank(selfValueSplitBy) && CollectionUtil.isNotEmpty(targetValues)) {
|
||||||
Set<Object> newTargetValues = new HashSet<>();
|
Set<Object> newTargetValues = new HashSet<>();
|
||||||
for (Object targetValue : targetValues) {
|
for (Object targetValue : targetValues) {
|
||||||
if (targetValue == null) {
|
if (targetValue == null) {
|
||||||
@ -60,7 +60,7 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
if (!(targetValue instanceof String)) {
|
if (!(targetValue instanceof String)) {
|
||||||
throw FlexExceptions.wrap("split field only support String type, but current type is: \"" + targetValue.getClass().getName() + "\"");
|
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) {
|
for (String splitValue : splitValues) {
|
||||||
//优化分割后的数据类型(防止在数据库查询时候出现隐式转换)
|
//优化分割后的数据类型(防止在数据库查询时候出现隐式转换)
|
||||||
newTargetValues.add(ConvertUtil.convert(splitValue, targetFieldWrapper.getFieldType()));
|
newTargetValues.add(ConvertUtil.convert(splitValue, targetFieldWrapper.getFieldType()));
|
||||||
@ -101,8 +101,8 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (StringUtil.isNotBlank(selfFieldSplitBy)) {
|
if (StringUtil.isNotBlank(selfValueSplitBy)) {
|
||||||
String[] splitValues = ((String) selfValue).split(selfFieldSplitBy);
|
String[] splitValues = ((String) selfValue).split(selfValueSplitBy);
|
||||||
targetMappingValues.addAll(Arrays.asList(splitValues));
|
targetMappingValues.addAll(Arrays.asList(splitValues));
|
||||||
} else {
|
} else {
|
||||||
targetMappingValues.add((String) selfValue);
|
targetMappingValues.add((String) selfValue);
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class PatientVO1 implements Serializable {
|
|||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "diseaseIds",
|
selfField = "diseaseIds",
|
||||||
selfFieldSplitBy = ",", //使用 , 进行分割
|
selfValueSplitBy = ",", //使用 , 进行分割
|
||||||
targetTable = "tb_disease", //只获取某个字段值需要填入目标表名
|
targetTable = "tb_disease", //只获取某个字段值需要填入目标表名
|
||||||
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
||||||
valueField = "name" //测试只获取某个字段值是否正常
|
valueField = "name" //测试只获取某个字段值是否正常
|
||||||
@ -50,14 +50,14 @@ public class PatientVO1 implements Serializable {
|
|||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "tagIds",
|
selfField = "tagIds",
|
||||||
selfFieldSplitBy = "/", //使用 / 进行分割
|
selfValueSplitBy = "/", //使用 / 进行分割
|
||||||
targetField = "tagId" //测试目标字段是数字类型是否正常转换
|
targetField = "tagId" //测试目标字段是数字类型是否正常转换
|
||||||
)
|
)
|
||||||
private List<Tag> tagList;
|
private List<Tag> tagList;
|
||||||
|
|
||||||
@RelationOneToMany(
|
@RelationOneToMany(
|
||||||
selfField = "diseaseIds",
|
selfField = "diseaseIds",
|
||||||
selfFieldSplitBy = ",", //使用 , 进行分割
|
selfValueSplitBy = ",", //使用 , 进行分割
|
||||||
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
targetField = "diseaseId", //测试目标字段是字符串类型是否正常转换
|
||||||
mapKeyField = "diseaseId" //测试Map映射
|
mapKeyField = "diseaseId" //测试Map映射
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user