Mybatis-Plus之通用枚举
14、Mybatis-Plus之通用枚举
表中的有些字段值是固定的,例如性别(男或女),此时我们可以使用MyBatis-Plus的通用枚举来实现
1、数据库表添加字段sex
2、创建通用枚举类型
1 | package com.jw.cloud.mybatisplus.enums; |
1 | ``` |
package com.jw.cloud.mybatisplus.enums;
import com.baomidou.mybatisplus.annotation.IEnum;
/**
- @author JoyWu
*/
public enum JobEnum implements IEnum
/**
* 医生
*/
Doctor(1, “医生”,”WWW”),
Teacher(2, “老师”,”qqqq”),
Programmer(3, “程序员”,”pppp”),
Driver(4, “司机”,”oooo”);
public int jobId;
public String jobName;
public String des;
JobEnum(int jobId, String jobName, String des) {
this.jobId = jobId;
this.jobName = jobName;
this.des = des;
}
public int getJobId() {
return jobId;
}
public String getJobName() {
return jobName;
}
public static JobEnum getJobEnum(int JobId) {
for (JobEnum jobEnum : values()) {
if (jobEnum.getJobId() == JobId) {
return jobEnum;
}
}
return null;
}
@Override
public Integer getValue() {
return this.jobId;
}
}
1 |
|
4、测试
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ashley的个人博客空间!