wrapper包裝枚舉插件
wrapper 插件
包裝枚舉插件(例如:0或1 包裝成男或女)
使用
1.引入jar包,實(shí)體類加入@Wrapper注解,指定dictData字典(必填),dictType字典類型(必填),name屬性自定義名稱(可選)
/**
* 性別 0 男 1女 數(shù)組方式
*/
@Wrapper(dictData = {"0:男","1:女"},dictType = "array",name = "demo")
private int sex;
/**
* 性別 0 男 1女 配置方式: 如果是配置方式,wrapper.properties在配置 sex.0=男 sex.1=女 強(qiáng)制:類型.狀態(tài)碼=值
*/
@Wrapper(dictData = {"sex.0","sex.1"},dictType = "config", name = "demo")
private int sex;
2.在需要數(shù)據(jù)轉(zhuǎn)換地方調(diào)用方法
@GetMapping("/")
public List<Map<String, Object>> hello() {
// 初始化數(shù)據(jù)
List<Student> students = new ArrayList<>();
for (int i = 0; i <= 10; i++ ) {
Student student = new Student(i, "張三" + i , i % 2);
students.add(student);
}
// 調(diào)用
return ControllerWrapper.getInstance().wrap(students);
}
3.效果展示
[
{
name: "張三0",
id: "0",
demo: "男"
},
{
name: "張三1",
id: "1",
demo: "女"
},
{
name: "張三2",
id: "2",
demo: "男"
},
{
name: "張三3",
id: "3",
demo: "女"
}
....
]評(píng)論
圖片
表情
