1.数据库字段 orderType int(1): 1表示自营商城、 2表示窗口售票、 3表示OTA分销 、4表示自有分销、5表示云平台商城
2.项目中建对应的枚举类:
@Getter
public enum OrderTypeEnum {
ZYSC(1,"自营商城"),
CKSP(2,"窗口售票"),
YPT(5,"云平台商城"),
OTAFX(3,"OTA分销"),
ZYFX(4,"自有分销");
@EnumValue //表示插入进数据库的值
private final int code;
@JsonValue
private final String name;
OrderTypeEnum(int code, String name) {
this.code = code;
this.name = name;
}
@Override //必须重写toString方法,否则不生效
public String toString() {
return name;
}
public static OrderTypeEnum getEnum(int code){
return Arrays.stream(OrderTypeEnum.values()).filter(e-> Objects.equals(code,e.getCode())).findFirst().orElse(null);
}
}
3.在application.yml中加入配置项:mybatis-plus.typeEnumsPackage 如下:
mybatis-plus:
mapper-locations: classpath:mapper/*Mapper.xml
#配置与数据库对应的枚举包
typeEnumsPackage: com.***.***.enums
configuration:
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler