java获取字典表数据,利用注解完成字典表数据对应

设计思路:

1、首先将字典表的数据以Map的形式进行初始化,key格式为type+"@"+code,value值为正常回显的值,如"ta_sex"+"@"+"1", "男"

2、建立DictAcc注解,code代表是数据库字段还是需要回显的标识,type存储类型如ta_sex

@Target(ElementType.FIELD)

@Retention(RetentionPolicy.RUNTIME)

public @interface DictACC {

public String code();

public String type();

}

3.建立一个类BV,code表示数据库存储的名字,name表示需要回显的名字

public class BV {

public final static String code="code";

public final static String name="name";

}

4.在pojo中字段sex,再建立sex_n表示要回显的字段(_n必须对应)

public class User {

@DictACC(code = BV.code, type = "ta_orgType")

public String orgType="1";

@DictACC(code = BV.name, type =

你可能感兴趣的:(java获取字典表数据)