IWithCode 相关接口的使用调整。
parent
aa7f10008f
commit
e972899fbb
|
@ -3,6 +3,9 @@ package xyz.zhouxy.plusone.jdbc;
|
||||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.exception.IWithCode;
|
||||||
|
import xyz.zhouxy.plusone.commons.exception.IWithIntCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扩展了 {@link BeanPropertySqlParameterSource},在将 POJO 转换为
|
* 扩展了 {@link BeanPropertySqlParameterSource},在将 POJO 转换为
|
||||||
* {@link org.springframework.jdbc.core.namedparam.SqlParameterSource} 时,
|
* {@link org.springframework.jdbc.core.namedparam.SqlParameterSource} 时,
|
||||||
|
@ -25,8 +28,14 @@ public class BeanPropertyParamSource extends BeanPropertySqlParameterSource {
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getValue(String paramName) throws IllegalArgumentException {
|
public Object getValue(String paramName) throws IllegalArgumentException {
|
||||||
Object value = super.getValue(paramName);
|
Object value = super.getValue(paramName);
|
||||||
if (value instanceof Enum) {
|
if (value instanceof Enum<?> e) {
|
||||||
return ((Enum<?>) value).ordinal();
|
if (value instanceof IWithCode<?> c) {
|
||||||
|
return c.getCode();
|
||||||
|
}
|
||||||
|
if (value instanceof IWithIntCode c) {
|
||||||
|
return c.getCode();
|
||||||
|
}
|
||||||
|
return e.ordinal();
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import xyz.zhouxy.plusone.commons.exception.IWithIntCode;
|
||||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||||
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
||||||
|
@ -129,12 +130,28 @@ public class Menu extends AggregateRoot<Long> implements IWithOrderNumber, IWith
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MenuType {
|
public enum MenuType implements IWithIntCode {
|
||||||
MENU_LIST, MENU_ITEM;
|
MENU_LIST(0), MENU_ITEM(1);
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
private MenuType(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonValue
|
@JsonValue
|
||||||
public int value() {
|
@Override
|
||||||
return ordinal();
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MenuType valueOf(int code) {
|
||||||
|
for (MenuType value : values()) {
|
||||||
|
if (value.code == code) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new EnumConstantNotPresentException(MenuType.class, Integer.toString(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue