当前位置:网站首页>Sql语法中循环的使用
Sql语法中循环的使用
2022-06-26 05:34:00 【杰拉德·皮克·谢】
sql批量插入
// mapper
Integer addUser(@Param("addUser") List<addUser> addUser();
// xml
<insert id="addUser">
INSERT INTO 用户表名
(姓名, 年龄, 性别)
VALUES
<foreach collection="addUser" item="user" separator=",">
(#{
user.姓名},
#{
user.年龄},
#{
user.性别})
</foreach>
</insert>
sql批量修改
- 在批量修改中可以恰当使用 if 语句 实现一句多用的效果,有助于提高代码的复用性
// mapper
Integer updateAll(@Param("user") List<User> userList);
// mxl
<update id="updateAll">
UPDATE official_mean_dev_rank
<foreach collection="user" item="u" separator=";">
<trim prefix="set" suffixOverrides=",">
<if test="u.姓名!= null">
user_name = #{
u.姓名},
</if>
<if test="u.年龄!= null">
年龄= #{
u.年龄},
</if>
<if test="u.性别!= null">
性别= #{
u.性别},
</if>
gmt_update = CURRENT_TIMESTAMP,
</trim>
WHERE id = #{
user.id}
</foreach>
</update>
单一属性批量查询
- 在sql 语法中
IN操作符允许您在 WHERE 子句中规定多个值。 - 思路 1.得到属性集合 2.在xml 中 循环填充 一次性查询
<foreach item='item' index='index' collection='atpTypes' open='(' separator=',' close=')'>#{item}</foreach>
// mapper
List<User> userNum(@Param("userClass") List<Integer> userClass);
// xml
<!--循环查询-->
<select id="userNum" resultType="com.xxx.xx.vo.User">
select u.* from t_user u
LEFT JOIN dept d ON d.id = u.pid
where
in <foreach item='item' index='index' collection='atpTypes' open='(' separator=',' close=')'>#{
item}</foreach>
</select>
边栏推荐
- LeetCode_ Binary search tree_ Simple_ 108. convert an ordered array to a binary search tree
- 2021年OWASP-TOP10
- ZigBee learning in simple terms lesson 3 external interruption
- Life is so fragile
- 二次bootloader关于boot28.asm应用的注意事项,28035的
- Daily production training report (17)
- C# 39. Conversion between string type and byte[] type (actual measurement)
- data = self._data_queue.get(timeout=timeout)
- cartographer_ optimization_ problem_ 2d
- Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
猜你喜欢
![C# 40. Byte[] to hexadecimal string](/img/3e/1b8b4e522b28eea4faca26b276a27b.png)
C# 40. Byte[] to hexadecimal string

cartographer_pose_graph_2d
转帖——不要迷失在技术的海洋中

Apktool tool usage document

pytorch(网络模型)

Setting pseudo static under fastadmin Apache

Red team scoring method statistics

cartographer_ backend_ constraint

SDN based DDoS attack mitigation

Replacing domestic image sources in openwrt for soft routing (take Alibaba cloud as an example)
随机推荐
[activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
Two step processing of string regular matching to get JSON list
cartographer_ fast_ correlative_ scan_ matcher_ 2D branch and bound rough matching
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
二次bootloader关于boot28.asm应用的注意事项,28035的
uniCloud云开发获取小程序用户openid
[PHP] PHP two-dimensional array is sorted by multiple fields
【MYSQL】MySQL 百万级数据量分页查询方法及其优化
无线网络存在的安全问题及现代化解决方案
cartographer_pose_graph_2d
The news of thunderbolt
数据存储:MySQL之InnoDB与MyISAM的区别
cartographer_ backend_ constraint
Leetcode513.找出树的左下角的值
Uni app ceiling fixed style
pytorch(网络模型)
[upsampling method opencv interpolation]
Leetcode513. Find the value in the lower left corner of the tree
写在父亲节前
Leetcode114. 二叉树展开为链表