# 包装枚举插件 **Repository Path**: yangyouwang/wrapper ## Basic Information - **Project Name**: 包装枚举插件 - **Description**: 包装枚举插件 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-20 - **Last Updated**: 2025-01-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## wrapper 插件 包装枚举插件(例如:0或1 包装成男或女) ### 使用 1.引入jar包,实体类加入@Wrapper注解,指定dictData字典(必填),dictType字典类型(必填),name属性自定义名称(可选) ``` /** * 性别 0 男 1女 数组方式 */ @Wrapper(dictData = {"0:男","1:女"},dictType = "array",name = "demo") private int sex; ``` ``` /** * 性别 0 男 1女 配置方式: 如果是配置方式,wrapper.properties在配置 sex.0=男 sex.1=女 强制:类型.状态码=值 */ @Wrapper(dictData = {"sex.0","sex.1"},dictType = "config", name = "demo") private int sex; ``` 2.在需要数据转换地方调用方法 ``` @GetMapping("/") public List> hello() { // 初始化数据 List students = new ArrayList<>(); for (int i = 0; i <= 10; i++ ) { Student student = new Student(i, "张三" + i , i % 2); students.add(student); } // 调用 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: "女" } .... ] ```