当前位置:网站首页>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>
边栏推荐
猜你喜欢
Posting - don't get lost in the ocean of Technology

There are applications related to web network request API in MATLAB (under update)

cartographer_ local_ trajectory_ builder_ 2d

9 common classes

Recursively traverse directory structure and tree presentation

pytorch(网络模型)

How to ensure the efficiency and real-time of pushing large-scale group messages in mobile IM?

Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
![[upsampling method opencv interpolation]](/img/6b/5e8f3c2844f0cbbbf03022e0efd5f0.png)
[upsampling method opencv interpolation]

Experience of reading the road to wealth and freedom
随机推荐
As promised: Mars, the mobile terminal IM network layer cross platform component library used by wechat, has been officially open source
Navicat如何将当前连接信息复用另一台电脑
Life is so fragile
转帖——不要迷失在技术的海洋中
Tp5.0 framework PDO connection MySQL error: too many connections solution
Positioning setting horizontal and vertical center (multiple methods)
Something about MariaDB
操作符的优先级、结合性、是否控制求值顺序【详解】
[MySQL] MySQL million level data paging query method and its optimization
vscode config
旧情书
thread priority
Written before father's Day
生命原来如此脆弱
cartographer_pose_graph_2d
Redis installation on Linux
Command line interface of alluxio
使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告
cartographer_local_trajectory_builder_2d
[red team] what preparations should be made to join the red team?