updateByPrimaryKeySelective 接收的参数为对应于数据库的实体类对象,利用字段的自动匹配进行更新表的操作,如果传入obj对象中的某个属性值为null,则不进行数据库对应字段的更新。
与updateByPrimaryKeySelective的区别在于,如果传入的obj对象中某个属性值为null,会将对应的数据库字段赋值为null。
User类
Class User{
Integer id;
String name;
Integer age;
String address;
}
id | name | age | address |
---|---|---|---|
1 | 张三 | 19 | 重庆 |
2 | 李四 | 20 | 贵州 |
User对象
创建user对象,属性为:id=1,name=张三,age=22, address=null;
利用通用mapper分别调用两种方法: UserMapper.updateByPrimaryKeySelective(user)的执行结果:
id | name | age | address |
---|---|---|---|
1 | 张三 | 22 | 重庆 |
2 | 李四 | 20 | 贵州 |
UserMapper.updateByPrimaryKey(user)的执行结果:
id | name | age | address |
---|---|---|---|
1 | 张三 | 22 | null |
2 | 李四 | 20 | 贵州 |
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有