mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
refactor: EnumWrapper的getEnumValue方法如果没有注解,则使用枚举name返回
This commit is contained in:
parent
7d24d19fbd
commit
8eb8807ac8
@ -42,4 +42,12 @@ public class TypeHandlerObject implements Serializable {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TypeHandlerObject{"
|
||||||
|
+ "value=" + value
|
||||||
|
+ ", typeHandler=" + typeHandler.getClass().getSimpleName()
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,17 +66,17 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
|||||||
|
|
||||||
|
|
||||||
public static QueryCondition create(String schema, String table, String column, String logic, Object value) {
|
public static QueryCondition create(String schema, String table, String column, String logic, Object value) {
|
||||||
QueryCondition condition = new QueryCondition();
|
return create(new QueryColumn(schema, table, column), logic, value);
|
||||||
condition.setColumn(new QueryColumn(schema, table, column));
|
|
||||||
condition.setLogic(logic);
|
|
||||||
condition.setValue(value);
|
|
||||||
return condition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QueryCondition create(QueryColumn queryColumn, Object value) {
|
public static QueryCondition create(QueryColumn queryColumn, Object value) {
|
||||||
return create(queryColumn, SqlConsts.EQUALS, value);
|
return create(queryColumn, SqlConsts.EQUALS, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static QueryCondition create(QueryColumn queryColumn, SqlOperator logic, Object value) {
|
||||||
|
return create(queryColumn, logic.getValue(), value);
|
||||||
|
}
|
||||||
|
|
||||||
public static QueryCondition create(QueryColumn queryColumn, String logic, Object value) {
|
public static QueryCondition create(QueryColumn queryColumn, String logic, Object value) {
|
||||||
QueryCondition condition = new QueryCondition();
|
QueryCondition condition = new QueryCondition();
|
||||||
condition.setColumn(queryColumn);
|
condition.setColumn(queryColumn);
|
||||||
@ -85,14 +85,6 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
|||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QueryCondition create(QueryColumn queryColumn, SqlOperator logic, Object value) {
|
|
||||||
QueryCondition condition = new QueryCondition();
|
|
||||||
condition.setColumn(queryColumn);
|
|
||||||
condition.setLogic(logic.getValue());
|
|
||||||
condition.setValue(value);
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueryColumn getColumn() {
|
public QueryColumn getColumn() {
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -700,11 +700,7 @@ public class TableInfo {
|
|||||||
// fixed: https://gitee.com/mybatis-flex/mybatis-flex/issues/I7TFBK
|
// fixed: https://gitee.com/mybatis-flex/mybatis-flex/issues/I7TFBK
|
||||||
if (value.getClass().isEnum()) {
|
if (value.getClass().isEnum()) {
|
||||||
EnumWrapper enumWrapper = EnumWrapper.of(value.getClass());
|
EnumWrapper enumWrapper = EnumWrapper.of(value.getClass());
|
||||||
if (enumWrapper.hasEnumValueAnnotation()) {
|
value = enumWrapper.getEnumValue((Enum) value);
|
||||||
value = enumWrapper.getEnumValue((Enum) value);
|
|
||||||
} else {
|
|
||||||
value = ((Enum<?>) value).name();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,10 +88,25 @@ public class EnumWrapper<E extends Enum<E>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取枚举值
|
||||||
|
* 顺序:
|
||||||
|
* 1、@EnumValue标识的get方法
|
||||||
|
* 2、@EnumValue标识的属性
|
||||||
|
* 3、没有使用@EnumValue,取枚举name
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Object getEnumValue(E object) {
|
public Object getEnumValue(E object) {
|
||||||
try {
|
try {
|
||||||
return getterMethod != null ? getterMethod.invoke(object) : property.get(object);
|
if (getterMethod != null) {
|
||||||
|
return getterMethod.invoke(object);
|
||||||
|
} else if(property != null){
|
||||||
|
return property.get(object);
|
||||||
|
} else {
|
||||||
|
return object.name();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw FlexExceptions.wrap(e);
|
throw FlexExceptions.wrap(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user