MyBatis-Plus updateById方法更新不了空字符串null解决方法

1 问题

在用mybatis-plus封装的updateById方法来更新数据时,想把一个字段设置为null值,但是发现更新后数据没有为null还是原来的值,这是因为mybatis-plus在更新的时候做了null判断,默认不更新为null的传参。

 

2 解决方法

在实体类对应的字段上加注解@TableField(strategy=FieldStrategy.IGNORED),忽略null值的判断,例如

/**
 * 经营许可证编号
 */
@TableField(strategy = FieldStrategy.IGNORED)
private String businessLicenseNo;

当@TableField注解有多个值时

/**
 * 经营许可证编号
 */
@TableField(value = "business_license_no", strategy = FieldStrategy.IGNORED)
private String businessLicenseNo;

猜你喜欢

转载自blog.csdn.net/weixin_41146000/article/details/103697679