IWithCode 相关接口的使用调整。
This commit is contained in:
@@ -3,6 +3,9 @@ package xyz.zhouxy.plusone.jdbc;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.exception.IWithCode;
|
||||
import xyz.zhouxy.plusone.commons.exception.IWithIntCode;
|
||||
|
||||
/**
|
||||
* 扩展了 {@link BeanPropertySqlParameterSource},在将 POJO 转换为
|
||||
* {@link org.springframework.jdbc.core.namedparam.SqlParameterSource} 时,
|
||||
@@ -17,17 +20,23 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
public class BeanPropertyParamSource extends BeanPropertySqlParameterSource {
|
||||
|
||||
public BeanPropertyParamSource(Object object) {
|
||||
super(object);
|
||||
}
|
||||
public BeanPropertyParamSource(Object object) {
|
||||
super(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getValue(String paramName) throws IllegalArgumentException {
|
||||
Object value = super.getValue(paramName);
|
||||
if (value instanceof Enum) {
|
||||
return ((Enum<?>) value).ordinal();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getValue(String paramName) throws IllegalArgumentException {
|
||||
Object value = super.getValue(paramName);
|
||||
if (value instanceof Enum<?> e) {
|
||||
if (value instanceof IWithCode<?> c) {
|
||||
return c.getCode();
|
||||
}
|
||||
if (value instanceof IWithIntCode c) {
|
||||
return c.getCode();
|
||||
}
|
||||
return e.ordinal();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user