UpdateJoinWrapperBuilder
UpdateJoinWrapperBuilder是FastCrud提供的一个builder类: 指定FastDTO类型、指定参数即可构造目标UpdateJoinWrapper实例。
UpdateJoinWrapper是MPJ中用于更新的wrapper,详见MPJ官网
eg1: 基础
java
StudentPageVO model = ...; // 接口传入或手动构造
UpdateJoinWrapper<Student> wrapper = new UpdateJoinWrapperBuilder<Student, StudentPageVO>(StudentPageVO.class)
.set(model)
.where(w -> w.eq(Student::getId, 1))
.build();
baseMapper.updateJoin(null, wrapper);这个例子构造一个UpdateJoinWrapper对象, 并且其中的from、join都将从StudentPageVO中解析, 而update语句中的set、where 为自定义, set——将把model中的所有属性值持久化到数据库。
eg2: 进阶
有时我们希望在上面基础上关联更多的表(这些表并没有在StudentPageVO中声明join信息), 并且更新这些表的字段值。
java
StudentPageVO model = ...; // 接口传入或手动构造
UpdateJoinWrapper<Student> wrapper = new UpdateJoinWrapperBuilder<Student, StudentPageVO>(StudentPageVO.class)
.set(model)
.appendSet(w -> w.set(Student::getName, "李四")
.set(StudentSensitive::getAddress, "浙江省嘉兴市")
.set(StudentCertificate::getNumber, "124"))
.appendJoin(w -> w.leftJoin(StudentCertificate.class, StudentCertificate::getStudentId, Student::getId))
.where(w -> w.eq(Student::getId, 1))
.build();
baseMapper.updateJoin(null, wrapper);上面这个例子中, Student和StudentSensitive在StudentPageVO中是有声明的, 而StudentCertificate是没有声明的, 这里通过appendSet扩展了set部分。
WARNING
- model中如果name值为"张三", 最终更新的name值将为"李四"。appendSet是后定义的,将覆盖set(model)。
UpdateJoinWrapperBuilder中的方法注意append*和无append的区别
更多详见此类源码