Skip to content

NestedResultEntityField 注解 VO映射 - 内嵌类字段映射

说明

@NestedResultEntity 注解是VO类映射 VO内的内嵌类的
但是 要是字段名字和实体类名字不一样怎么办?这时候@NestedResultEntityField的作用就来,它就是为解决字段名字不一样而设计的

属性说明

属性是否可空默认值说明
value对应的内嵌类实体类的字段名字

如何用?

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

    private Integer id;
    
    private String userName;

    // 此处字段类型可以实体类 可VO
    @NestedResultEntity(target = SysRole.class)
    private NestedSysRoleVo role;
}
java
@Data
public class NestedSysRoleVo {

    private Integer id;

    @NestedResultEntityField("roleName")
    private String otherName;
}
java
@Service
public class Test{

    @Autowired
    private SysUserMapper sysUserMapper;

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