mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
refactor: rename "targetFieldBind" to "valueField"
This commit is contained in:
parent
2562505139
commit
0f4f31a30e
@ -354,7 +354,7 @@ public class Account implements Serializable {
|
|||||||
|
|
||||||
Relation结果集只使用某个字段值-`since v1.6.6`
|
Relation结果集只使用某个字段值-`since v1.6.6`
|
||||||
|
|
||||||
`RelationOneToOne`、`RelationOneToMany`、`RelationManyToOne`、`RelationManyToMany`新增属性`targetFieldBind`
|
`RelationOneToOne`、`RelationOneToMany`、`RelationManyToOne`、`RelationManyToMany`新增属性`valueField`
|
||||||
```java {7-11}
|
```java {7-11}
|
||||||
/**
|
/**
|
||||||
* 目标对象的关系实体类的属性绑定
|
* 目标对象的关系实体类的属性绑定
|
||||||
@ -362,9 +362,9 @@ Relation结果集只使用某个字段值-`since v1.6.6`
|
|||||||
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
||||||
* @return 属性名称
|
* @return 属性名称
|
||||||
*/
|
*/
|
||||||
String targetFieldBind() default "";
|
String valueField() default "";
|
||||||
```
|
```
|
||||||
> 注解其他属性配置使用不变,当配置了`targetFieldBind`值时,只提取目标对象关系实体类的该属性
|
> 注解其他属性配置使用不变,当配置了`valueField`值时,只提取目标对象关系实体类的该属性
|
||||||
>
|
>
|
||||||
> 注意:因为不是对象接收,所以该配置需要强制配置注解`targetTable`属性(因为是某个字段接收,并不是某个实体对应的表,所以需要增加`targetTable`获取目标表信息)
|
> 注意:因为不是对象接收,所以该配置需要强制配置注解`targetTable`属性(因为是某个字段接收,并不是某个实体对应的表,所以需要增加`targetTable`获取目标表信息)
|
||||||
>
|
>
|
||||||
@ -389,7 +389,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_id_card",
|
targetTable = "tb_id_card",
|
||||||
targetField = "id",
|
targetField = "id",
|
||||||
targetFieldBind = "idNumber"
|
valueField = "idNumber"
|
||||||
)
|
)
|
||||||
//该处可以定义其他属性名,不一定要是目标对象的字段名
|
//该处可以定义其他属性名,不一定要是目标对象的字段名
|
||||||
private String idNumberCustomFieldName;
|
private String idNumberCustomFieldName;
|
||||||
@ -398,7 +398,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_user_order",
|
targetTable = "tb_user_order",
|
||||||
targetField = "userId",
|
targetField = "userId",
|
||||||
targetFieldBind = "orderId"
|
valueField = "orderId"
|
||||||
)
|
)
|
||||||
private List<Integer> orderIdList;
|
private List<Integer> orderIdList;
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_role",
|
targetTable = "tb_role",
|
||||||
targetField = "roleId",
|
targetField = "roleId",
|
||||||
targetFieldBind = "roleName",
|
valueField = "roleName",
|
||||||
joinTable = "tb_user_role",
|
joinTable = "tb_user_role",
|
||||||
joinSelfColumn = "user_id",
|
joinSelfColumn = "user_id",
|
||||||
joinTargetColumn = "role_id"
|
joinTargetColumn = "role_id"
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public @interface RelationManyToMany {
|
|||||||
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
||||||
* @return 属性名称
|
* @return 属性名称
|
||||||
*/
|
*/
|
||||||
String targetFieldBind() default "";
|
String valueField() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当映射是一个 map 时,使用哪个内容来当做 map 的 Key
|
* 当映射是一个 map 时,使用哪个内容来当做 map 的 Key
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public @interface RelationManyToOne {
|
|||||||
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
||||||
* @return 属性名称
|
* @return 属性名称
|
||||||
*/
|
*/
|
||||||
String targetFieldBind() default "";
|
String valueField() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 中间表名称,一对一的关系是通过通过中间表维护时,需要添加此项配置。
|
* 中间表名称,一对一的关系是通过通过中间表维护时,需要添加此项配置。
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public @interface RelationOneToMany {
|
|||||||
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
||||||
* @return 属性名称
|
* @return 属性名称
|
||||||
*/
|
*/
|
||||||
String targetFieldBind() default "";
|
String valueField() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当映射是一个 map 时,使用哪个内容来当做 map 的 Key
|
* 当映射是一个 map 时,使用哪个内容来当做 map 的 Key
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public @interface RelationOneToOne {
|
|||||||
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
* 当字段不为空串时,只进行某个字段赋值(使用对应字段类型接收)
|
||||||
* @return 属性名称
|
* @return 属性名称
|
||||||
*/
|
*/
|
||||||
String targetFieldBind() default "";
|
String valueField() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 中间表名称,一对一的关系是通过通过中间表维护时,需要添加此项配置。
|
* 中间表名称,一对一的关系是通过通过中间表维护时,需要添加此项配置。
|
||||||
|
|||||||
@ -46,8 +46,10 @@ abstract class AbstractRelation<SelfEntity> {
|
|||||||
protected String targetSchema;
|
protected String targetSchema;
|
||||||
protected String targetTable;
|
protected String targetTable;
|
||||||
protected Field targetField;
|
protected Field targetField;
|
||||||
protected String targetFieldBind;
|
|
||||||
protected boolean onlyTargetFieldBind;
|
protected String valueField;
|
||||||
|
protected boolean onlyQueryValueField;
|
||||||
|
|
||||||
protected Class<?> targetEntityClass;
|
protected Class<?> targetEntityClass;
|
||||||
protected TableInfo targetTableInfo;
|
protected TableInfo targetTableInfo;
|
||||||
protected FieldWrapper targetFieldWrapper;
|
protected FieldWrapper targetFieldWrapper;
|
||||||
@ -64,7 +66,7 @@ abstract class AbstractRelation<SelfEntity> {
|
|||||||
protected QueryColumn conditionColumn;
|
protected QueryColumn conditionColumn;
|
||||||
protected String[] selectColumns;
|
protected String[] selectColumns;
|
||||||
|
|
||||||
public AbstractRelation(String selfField, String targetSchema, String targetTable, String targetField, String targetFieldBind,
|
public AbstractRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField,
|
||||||
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
||||||
String dataSource, Class<SelfEntity> entityClass, Field relationField,
|
String dataSource, Class<SelfEntity> entityClass, Field relationField,
|
||||||
String extraCondition, String[] selectColumns
|
String extraCondition, String[] selectColumns
|
||||||
@ -93,14 +95,14 @@ abstract class AbstractRelation<SelfEntity> {
|
|||||||
this.targetField = ClassUtil.getFirstField(targetEntityClass, field -> field.getName().equals(targetField));
|
this.targetField = ClassUtil.getFirstField(targetEntityClass, field -> field.getName().equals(targetField));
|
||||||
this.targetFieldWrapper = FieldWrapper.of(targetEntityClass, targetField);
|
this.targetFieldWrapper = FieldWrapper.of(targetEntityClass, targetField);
|
||||||
|
|
||||||
this.targetFieldBind = targetFieldBind;
|
this.valueField = valueField;
|
||||||
this.onlyTargetFieldBind = StringUtil.isNotBlank(targetFieldBind);
|
this.onlyQueryValueField = StringUtil.isNotBlank(valueField);
|
||||||
|
|
||||||
this.conditionColumn = column(targetTable, targetTableInfo.getColumnByProperty(this.targetField.getName()));
|
this.conditionColumn = column(targetTable, targetTableInfo.getColumnByProperty(this.targetField.getName()));
|
||||||
|
|
||||||
if (onlyTargetFieldBind) {
|
if (onlyQueryValueField) {
|
||||||
//仅绑定字段时只需要查询关联列和该字段列即可
|
//仅绑定字段时只需要查询关联列和该字段列即可
|
||||||
this.selectColumns = new String[]{conditionColumn.getName(), targetTableInfo != null ? targetTableInfo.getColumnByProperty(this.targetFieldBind) : StringUtil.camelToUnderline(this.targetFieldBind)};
|
this.selectColumns = new String[]{conditionColumn.getName(), targetTableInfo != null ? targetTableInfo.getColumnByProperty(this.valueField) : StringUtil.camelToUnderline(this.valueField)};
|
||||||
} else {
|
} else {
|
||||||
if (ArrayUtil.isNotEmpty(selectColumns)) {
|
if (ArrayUtil.isNotEmpty(selectColumns)) {
|
||||||
if (ArrayUtil.contains(selectColumns, conditionColumn.getName())) {
|
if (ArrayUtil.contains(selectColumns, conditionColumn.getName())) {
|
||||||
@ -259,20 +261,20 @@ abstract class AbstractRelation<SelfEntity> {
|
|||||||
this.targetTable = targetTable;
|
this.targetTable = targetTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTargetFieldBind() {
|
public String getValueField() {
|
||||||
return targetFieldBind;
|
return valueField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetFieldBind(String targetFieldBind) {
|
public void setValueField(String valueField) {
|
||||||
this.targetFieldBind = targetFieldBind;
|
this.valueField = valueField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnlyTargetFieldBind() {
|
public boolean isOnlyQueryValueField() {
|
||||||
return onlyTargetFieldBind;
|
return onlyQueryValueField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnlyTargetFieldBind(boolean onlyTargetFieldBind) {
|
public void setOnlyQueryValueField(boolean onlyQueryValueField) {
|
||||||
this.onlyTargetFieldBind = onlyTargetFieldBind;
|
this.onlyQueryValueField = onlyQueryValueField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJoinTable() {
|
public String getJoinTable() {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class ManyToMany<SelfEntity> extends ToManyRelation<SelfEntity> {
|
|||||||
, annotation.targetSchema()
|
, annotation.targetSchema()
|
||||||
, annotation.targetTable()
|
, annotation.targetTable()
|
||||||
, getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField), "@RelationManyToMany.targetField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"")
|
, getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField), "@RelationManyToMany.targetField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"")
|
||||||
, annotation.targetFieldBind()
|
, annotation.valueField()
|
||||||
, annotation.joinTable()
|
, annotation.joinTable()
|
||||||
, annotation.joinSelfColumn()
|
, annotation.joinSelfColumn()
|
||||||
, annotation.joinTargetColumn()
|
, annotation.joinTargetColumn()
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class ManyToOne<SelfEntity> extends ToOneRelation<SelfEntity> {
|
|||||||
, annotation.targetTable()
|
, annotation.targetTable()
|
||||||
, getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField)
|
, getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField)
|
||||||
, "@RelationManyToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"")
|
, "@RelationManyToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"")
|
||||||
, annotation.targetFieldBind()
|
, annotation.valueField()
|
||||||
, annotation.joinTable()
|
, annotation.joinTable()
|
||||||
, annotation.joinSelfColumn()
|
, annotation.joinSelfColumn()
|
||||||
, annotation.joinTargetColumn()
|
, annotation.joinTargetColumn()
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class OneToMany<SelfEntity> extends ToManyRelation<SelfEntity> {
|
|||||||
, annotation.targetSchema()
|
, annotation.targetSchema()
|
||||||
, annotation.targetTable()
|
, annotation.targetTable()
|
||||||
, annotation.targetField()
|
, annotation.targetField()
|
||||||
, annotation.targetFieldBind()
|
, annotation.valueField()
|
||||||
, annotation.joinTable()
|
, annotation.joinTable()
|
||||||
, annotation.joinSelfColumn()
|
, annotation.joinSelfColumn()
|
||||||
, annotation.joinTargetColumn()
|
, annotation.joinTargetColumn()
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class OneToOne<SelfEntity> extends ToOneRelation<SelfEntity> {
|
|||||||
, annotation.targetSchema()
|
, annotation.targetSchema()
|
||||||
, annotation.targetTable()
|
, annotation.targetTable()
|
||||||
, annotation.targetField()
|
, annotation.targetField()
|
||||||
, annotation.targetFieldBind()
|
, annotation.valueField()
|
||||||
, annotation.joinTable()
|
, annotation.joinTable()
|
||||||
, annotation.joinSelfColumn()
|
, annotation.joinSelfColumn()
|
||||||
, annotation.joinTargetColumn()
|
, annotation.joinTargetColumn()
|
||||||
|
|||||||
@ -361,7 +361,7 @@ public class RelationManager {
|
|||||||
|
|
||||||
//仅绑定字段:As目标实体类 不进行字段绑定:As映射类型
|
//仅绑定字段:As目标实体类 不进行字段绑定:As映射类型
|
||||||
QueryWrapper queryWrapper = relation.buildQueryWrapper(targetValues);
|
QueryWrapper queryWrapper = relation.buildQueryWrapper(targetValues);
|
||||||
List<?> targetObjectList = mapper.selectListByQueryAs(queryWrapper, relation.isOnlyTargetFieldBind() ? relation.getTargetEntityClass() : relation.getMappingType());
|
List<?> targetObjectList = mapper.selectListByQueryAs(queryWrapper, relation.isOnlyQueryValueField() ? relation.getTargetEntityClass() : relation.getMappingType());
|
||||||
if (CollectionUtil.isNotEmpty(targetObjectList)) {
|
if (CollectionUtil.isNotEmpty(targetObjectList)) {
|
||||||
|
|
||||||
//递归查询
|
//递归查询
|
||||||
|
|||||||
@ -31,11 +31,11 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
protected long limit = 0;
|
protected long limit = 0;
|
||||||
|
|
||||||
|
|
||||||
public ToManyRelation(String selfField, String targetSchema, String targetTable, String targetField, String targetFieldBind,
|
public ToManyRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField,
|
||||||
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
||||||
String dataSource, Class<SelfEntity> selfEntityClass, Field relationField,
|
String dataSource, Class<SelfEntity> selfEntityClass, Field relationField,
|
||||||
String extraCondition, String[] selectColumns) {
|
String extraCondition, String[] selectColumns) {
|
||||||
super(selfField, targetSchema, targetTable, targetField, targetFieldBind,
|
super(selfField, targetSchema, targetTable, targetField, valueField,
|
||||||
joinTable, joinSelfColumn, joinTargetColumn,
|
joinTable, joinSelfColumn, joinTargetColumn,
|
||||||
dataSource, selfEntityClass, relationField,
|
dataSource, selfEntityClass, relationField,
|
||||||
extraCondition, selectColumns
|
extraCondition, selectColumns
|
||||||
@ -101,9 +101,9 @@ class ToManyRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
for (Object targetObject : targetObjectList) {
|
for (Object targetObject : targetObjectList) {
|
||||||
Object targetValue = targetFieldWrapper.get(targetObject);
|
Object targetValue = targetFieldWrapper.get(targetObject);
|
||||||
if (targetValue != null && targetMappingValues.contains(targetValue.toString())) {
|
if (targetValue != null && targetMappingValues.contains(targetValue.toString())) {
|
||||||
if (onlyTargetFieldBind) {
|
if (onlyQueryValueField) {
|
||||||
//仅绑定某个字段
|
//仅绑定某个字段
|
||||||
collection.add(FieldWrapper.of(targetObject.getClass(), targetFieldBind).get(targetObject));
|
collection.add(FieldWrapper.of(targetObject.getClass(), valueField).get(targetObject));
|
||||||
} else {
|
} else {
|
||||||
collection.add(targetObject);
|
collection.add(targetObject);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,10 +24,10 @@ import java.util.List;
|
|||||||
class ToOneRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
class ToOneRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
||||||
|
|
||||||
|
|
||||||
public ToOneRelation(String selfField, String targetSchema, String targetTable, String targetField, String targetFieldBind,
|
public ToOneRelation(String selfField, String targetSchema, String targetTable, String targetField, String valueField,
|
||||||
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
String joinTable, String joinSelfColumn, String joinTargetColumn,
|
||||||
String dataSource, Class<SelfEntity> selfEntityClass, Field relationField, String[] selectColumns) {
|
String dataSource, Class<SelfEntity> selfEntityClass, Field relationField, String[] selectColumns) {
|
||||||
super(selfField, targetSchema, targetTable, targetField, targetFieldBind,
|
super(selfField, targetSchema, targetTable, targetField, valueField,
|
||||||
joinTable, joinSelfColumn, joinTargetColumn,
|
joinTable, joinSelfColumn, joinTargetColumn,
|
||||||
dataSource, selfEntityClass, relationField,
|
dataSource, selfEntityClass, relationField,
|
||||||
null, selectColumns
|
null, selectColumns
|
||||||
@ -54,9 +54,9 @@ class ToOneRelation<SelfEntity> extends AbstractRelation<SelfEntity> {
|
|||||||
for (Object targetObject : targetObjectList) {
|
for (Object targetObject : targetObjectList) {
|
||||||
Object targetValue = targetFieldWrapper.get(targetObject);
|
Object targetValue = targetFieldWrapper.get(targetObject);
|
||||||
if (targetValue != null && targetMappingValue.equals(targetValue.toString())) {
|
if (targetValue != null && targetMappingValue.equals(targetValue.toString())) {
|
||||||
if (onlyTargetFieldBind) {
|
if (onlyQueryValueField) {
|
||||||
//仅绑定某个字段
|
//仅绑定某个字段
|
||||||
relationFieldWrapper.set(FieldWrapper.of(targetObject.getClass(), targetFieldBind).get(targetObject), selfEntity);
|
relationFieldWrapper.set(FieldWrapper.of(targetObject.getClass(), valueField).get(targetObject), selfEntity);
|
||||||
} else {
|
} else {
|
||||||
relationFieldWrapper.set(targetObject, selfEntity);
|
relationFieldWrapper.set(targetObject, selfEntity);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_id_card",
|
targetTable = "tb_id_card",
|
||||||
targetField = "id",
|
targetField = "id",
|
||||||
targetFieldBind = "idNumber"
|
valueField = "idNumber"
|
||||||
)
|
)
|
||||||
private String idNumberCustomFieldName;
|
private String idNumberCustomFieldName;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_user_order",
|
targetTable = "tb_user_order",
|
||||||
targetField = "userId",
|
targetField = "userId",
|
||||||
targetFieldBind = "orderId"
|
valueField = "orderId"
|
||||||
)
|
)
|
||||||
private List<Integer> orderIdList;
|
private List<Integer> orderIdList;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public class UserVO5 implements Serializable {
|
|||||||
selfField = "userId",
|
selfField = "userId",
|
||||||
targetTable = "tb_role",
|
targetTable = "tb_role",
|
||||||
targetField = "roleId",
|
targetField = "roleId",
|
||||||
targetFieldBind = "roleName",
|
valueField = "roleName",
|
||||||
joinTable = "tb_user_role",
|
joinTable = "tb_user_role",
|
||||||
joinSelfColumn = "user_id",
|
joinSelfColumn = "user_id",
|
||||||
joinTargetColumn = "role_id"
|
joinTargetColumn = "role_id"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user