0%

myBatis一次执行多条语句问题

需要在application.yml里面连接数据库时添加运行执行多条sql语句

&allowMultiQueries=true

1
2
3
4
5
6
7
8
9
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true
redis:
host: 127.0.0.1
port: 6379
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<update id="updateByListPrimaryKey" parameterType="java.util.List">
<foreach collection="productList" index="index" item="item" separator=";" >
update mall_product
<set>
<if test="item.categoryId != null">
category_id = #{item.categoryId,jdbcType=INTEGER},
</if>
<if test="item.name != null">
name = #{item.name,jdbcType=VARCHAR},
</if>
<if test="item.subtitle != null">
subtitle = #{item.subtitle,jdbcType=VARCHAR},
</if>
<if test="item.mainImage != null">
main_image = #{item.mainImage,jdbcType=VARCHAR},
</if>
<if test="item.subImages != null">
sub_images = #{item.subImages,jdbcType=VARCHAR},
</if>
<if test="item.detail != null">
detail = #{item.detail,jdbcType=VARCHAR},
</if>
<if test="item.price != null">
price = #{item.price,jdbcType=DECIMAL},
</if>
<if test="item.stock != null">
stock = #{item.stock,jdbcType=INTEGER},
</if>
<if test="item.status != null">
status = #{item.status,jdbcType=INTEGER},
</if>

</set>
where id = #{item.id,jdbcType=INTEGER}
</foreach>
</update>