当前使用版本(必填,否则不予处理)
3.3.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
@Test
void updateFullById() {
TestUser tsUser = new TestUser(new BigInteger("1"));
tsUser.setUserName("张三更新'");
tsUser.setAge(66);
tsUser.setModifyId(new BigInteger("3"));
System.err.println("返回值:"+testUserService.updateFullById(tsUser));
}
sql日志:
// 手动赋值的3
3
// 自动填充方法里的时间
2020-05-26T16:38:10.716
2020-05-26 16:38:10.724 INFO 9508 --- [ main] com.zaxxer.hikari.HikariDataSource : MyHikariCP - Starting...
2020-05-26 16:38:11.010 INFO 9508 --- [ main] com.zaxxer.hikari.HikariDataSource : MyHikariCP - Start completed.
Consume Time:62 ms 2020-05-26 16:38:11
Execute SQL:SELECT 1
Consume Time:71 ms 2020-05-26 16:38:11
Execute SQL:UPDATE test_user t SET t.modify_id = 3, t.modify_time = NULL, T.uid = NULL, t.user_name = '张三更新''', T.sex = NULL, t.age = 66, t.birthday = NULL, t.unit_id = NULL WHERE t.id = 1
返回值:1
重现步骤(如果有就写完整)
1、手动添加修改者 3不添加修改时间,可以保存到数据库
2、自动填充类
@Override
public void updateFill(MetaObject metaObject) {
log.info("start update fill ....");
BigInteger currentUserId = currentUserId();
Object modifyId = this.getFieldValByName(this.modifyId, metaObject);
if (modifyId == null) {
this.strictUpdateFill(metaObject, this.modifyId, BigInteger.class, currentUserId);
}
LocalDateTime now = LocalDateTime.now();
Object modifyTime = this.getFieldValByName(this.modifyTime, metaObject);
if (modifyTime == null) {
this.strictUpdateFill(metaObject, this.modifyTime, LocalDateTime.class, now);
}
// 走了 方法,有值
System.out.println(this.getFieldValByName(this.modifyId, metaObject));
System.out.println(this.getFieldValByName(this.modifyTime, metaObject));
}
3、xml语句
<update id="updateFullById" parameterType="TestUser" >
UPDATE test_user t
<set>
<include refid="UpdateFullFieldList">
<property name="joiner" value=""/>
</include>
</set>
WHERE t.id = #{id}
</update>
<sql id="UpdateFullFieldList">
<choose>
<when test="${joiner}modifyId != null">
t.modify_id = #{${joiner}modifyId},
</when>
<otherwise>
t.modify_id = 2,
</otherwise>
</choose>
<choose>
<when test="${joiner}modifyTime != null">
t.modify_time = #{${joiner}modifyTime},
</when>
<otherwise>
t.modify_time = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}uid != null and ${joiner}uid != ''">
t.uid = #{${joiner}uid},
</when>
<otherwise>
T.uid = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}userName != null and ${joiner}userName != ''">
t.user_name = #{${joiner}userName},
</when>
<otherwise>
T.user_name = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}sex != null and ${joiner}sex != ''">
t.sex = #{${joiner}sex},
</when>
<otherwise>
T.sex = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}age != null">
t.age = #{${joiner}age},
</when>
<otherwise>
t.age = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}birthday != null">
t.birthday = #{${joiner}birthday},
</when>
<otherwise>
t.birthday = NULL,
</otherwise>
</choose>
<choose>
<when test="${joiner}fkByUnitId != null and ${joiner}fkByUnitId.id != null">
t.unit_id = #{${joiner}fkByUnitId.id},
</when>
<otherwise>
t.unit_id = NULL,
</otherwise>
</choose>
</sql>
4、实体类
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
protected BigInteger modifyId;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
protected LocalDateTime modifyTime;
报错信息
无
Comment From: miemieYaho
因为set值是在ognl之后进行的,所以对应的字段不能判null