背景:使用mybatis-plus,想将某个字段原本不为null的值更新为null(数据库设计允许为null)。
推荐方法:使用UpdateWrapper方式更新
@Override
public boolean updateBookById(Long bookId) {
UpdateWrapper<BookEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("book_id", bookId);
updateWrapper.set("publish_time", null);
return super.update(updateWrapper);
}
如果直接调用该字段set方法set(null),或者直接拼接sql语句,可能存在执行更新方法后数据库字段值没有变的情况。