当前位置:网站首页>MP更新操作方式
MP更新操作方式
2022-08-02 04:36:00 【qq_45860901】
第一种:updateById的方式
这种方式需要传入实体类,生成的Sql,会包含所有的字段更新。
所以更推荐第二种。
User user = new User();
user.setUserId(1);
user.setAge(23);
userMapper.updateById(user);
第二种:使用update 和UpdateWrapper配合
这种方式可以只更新指定的几个字段。
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
updateWrapper
.set("age", 23); //set实现的是sql语句的update set age = 18的部分
.eq("name","张三") //eq实现的是sql 的where 后面的部分。
userMapper.update(null, updateWrapper); //第一个参数一定是null,才只会更新Wrapper里的指定字段。
其他:
编写mapper对应的方法的xml的sql代码
还可以使用MP的lamabda的updatewrapper。
边栏推荐
猜你喜欢
随机推荐
如果有些字段不想进行序列化怎么办?
P1012 [NOIP1998 Improve Group] Spelling
康威定律对于系统架构很重要吗?
力扣练习——37 复原IP地址
【MLT】MLT多媒体框架生产消费架构解析(一)
Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)
[QNX Hypervisor 2.2用户手册]9.20 vdev
UE4 局域网联机案例
vs2022 编译libmodbus源码
【Gazebo入门教程】第一讲 Gazebo的安装、UI界面、SDF文件介绍
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
IOT物联网概述及应用层架构入门篇
使用pycharm debug 深度学习代码
物联网通信协议全解析
【数字IC手撕代码】Verilog固定优先级仲裁器|题目|原理|设计|仿真
安全测试常见问题
区间和 离散化
论文速读:Homography Loss for Monocular 3D Object Detection
Learn about the sequential storage structure of binary tree - heap
HSCTF2022-re题解









