Skip to content

PutEnumValue 注解 VO注入枚举值

说明

PutEnumValue 是VO注解,不能应用在实体类上,用于根据数据库code,注入name的情况;例如状态code,查询后自动注入 状态name的场景

属性说明

属性是否可空默认值说明
source来源,对应的实体类
property对应的实体类的字段名
storey1存储层级,联表自己join自己时使用,一般不用管
target目标,对应的枚举类
codecode枚举的code字段名
valuename需要注入对应枚举的字段名
requiredfalse是否必须,true时,找不到对应的枚举会报错
defaultValue找不到时,默认值

如何用?

java
@Data
@ResultEntity(SysUser.class)
public class SysUserVo {

    private Integer id;
    
    private String userName;

    private String password;
    
    private Integer status;

    @PutEnumValue(source = SysUser.class, property = "status", target = StatusEnum.class)
    private String statusName;
}
java
public enum StatusEnum {
    
    ENABLE(1,"正常"),UNABLE(0,"禁用");
    
    private final Integer code;
    
    private final String name;

    StatusEnum(Integer code,String name){
        this.code= code;
        this.name=name;
    }
    
}
java
@Service
public class Test{

    @Autowired
    private SysUserMapper sysUserMapper;

    public void demo() {
        Pager<SysUserVo> pager = QueryChain.of(sysUserMapper)
                .eq(SysUser::getId,1)
                .like(SysUser::getUserName,"xxx")
                .returnType(SysUserVo.class)
                .paging(Pager.of(1,10));
    }
}

框架自动帮你 注入StatusEnum枚举对应的name名字