.updateById(DAO对象);Mybatis处理会把整个对象都给update掉,怎么样更新对象为null的情况

本文探讨了MyBatis中使用@TableField注解时遇到的问题,特别是如何避免更新null值字段,通过设置FieldStrategy.IGNORED策略来实现智能更新,防止无效的null值覆盖现有数据。

前言:

.updateById(DAO对象);Mybatis处理会把整个对象都给update掉,添加注解:@TableField(value = "news", strategy = FieldStrategy.IGNORED) 会全部的进行update哪怕是null 也会更新!

问题描述:

 解决办法:

/**
 * 数据源转化率(新源没有转化率的按照3算)模型2舆情
 */
@TableField(value = "convert_score_yq", strategy = FieldStrategy.IGNORED)
private Double convertScoreYq;

/**
 * 模型1得分
 */
@TableField(value = "model_total_score_news", strategy = FieldStrategy.IGNORED)
private Double modelTotalScoreNews;

/**
 * 模型2得分
 */
@TableField(value = "model_total_score_yq", strategy = FieldStrategy.IGNORED)
private Double modelTotalScoreYq;

 

运行的SQL:

==>  Preparing: UPDATE tbm_factor_score SET source_type_score_news=?, subject_type_score_news=?, subject_type_score_yq=?, range_type_score_news=?, title_importance_score_news=?, title_importance_score_yq=?, title_negative_score_news=?, title_negative_score_yq=?, media_column_score_news=?, media_column_score_yq=?, media_source_score_news=?, sentiment_score_news=?, sentiment_score_yq=?, convert_score_news=?, convert_score_yq=?, model_total_score_news=?, model_total_score_yq=?, update_user_id=?, create_time=?, update_time=? WHERE id=? 
==> Parameters: null, null, 0(Integer), null, null, 0(Integer), null, 0(Integer), null, 0(Integer), null, null, 90(Integer), 0.0(Double), 0.0(Double), null, 90.0(Double), 999(Integer), null, 2021-05-12 14:30:44.873(Timestamp), 11819695754372(Long)
<==    Updates: 1

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦思冥想行则将至

穷,有钱的大爷上个两分钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值