代码拉取完成,页面将自动刷新
当表中的字段为数据字典类型的值时,可使用数据字典关联来绑定表字段与数据字典的关联关系。 通过@BindDict注解,数据字典关联时无需写大量java代码和SQL关联查询,即可快速转换值字典value值为label。
使用@BindDict注解时需传两个参数,分别是type和field。
type表示关联的数据字典类型;
field表示关联字段。 示例如下:
@BindDict(type="USER_STATUS", field = "status")
private String statusLabel;
绑定单个实体(或实体对应的VO)使用**@BindEntity**注解进行处理,将得到关联表对应的单个实体。
@BindEntity(entity = Department.class, condition="this.department_id=id")
private Department department;
@BindEntity(entity = Department.class, condition="this.department_id=id", deepBind=true)
private DepartmentVO departmentVO;
绑定实体(或实体对应的VO)列表使用**@BindEntityList**注解进行处理,将得到关联表对应的实体列表。
// 关联其他表
@BindEntityList(entity = Department.class, condition="department_id=id")
private List<Department> departmentList;
// 关联自身,实现加载子级
@BindEntityList(entity = Department.class, condition ="id=parent_id")
private List<Department> children;
绑定字段使用**@BindField**注解进行处理,将得到关联表的目标字段的值(集合)。
@BindField(entity=Department.class, field="name", condition="department_id=id AND parent_id>=0")
private String deptName;
该关联会自动将相关信息查询并设置到voList中,适用于对已有的voList做处理,如:
//List<MyUserVO> voList = ...;
Binder.bindRelations(voList);
该关联会自动将vo所继承的父类的实体列表进行绑定并自动转型为voList,适用于对于非voList的实体列表等做处理,如:
// 查询单表获取Entity集合
// List<User> entityList = userService.list(queryWrapper);
// 转型并绑定关联
List<MyUserVO> voList = Binder.convertAndBindRelations(userList, MyUserVO.class);
// 绑定单个VO对象
service.getViewObject()
// 绑定多个VO集合
service.getViewObjectList()
使用依赖
<dependency>
<groupId>com.heaboy</groupId>
<artifactId>databind</artifactId>
<version>1.0.0</version>
<exclusions>
<!--如果使用spring boot 需要把面的依赖排除掉 -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
从diboot-core 精简出来的仅供单个数据绑定的小工具,不支持中间表联查,涉及到join还是建议自行写sql而不是通过工具 本项目依赖mybatis-plus从diboot项目中精简得出,如果你是spring项目可以将spring的依赖排除掉
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。