首页
点滴
Mybatis中一次执行多条语句
##### 有时候需要批量更新一些数据,会用到`
`标签来,其实就是用分号(;)隔开一次执行多条sql语句,比如看下面sql语句。 ```
update t_user set nickname = #{item.nickname} where id = #{item.id}
``` ##### 如果什么都没设置的话是会报错的 #### 1、需要在数据库连接信息里配置:allowMultiQueries=true 如: ``` url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Shanghai&useAffectedRows=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false ``` #### 2、如果用的是 Durid 数据库连接池的话那么 filters 不要配置 wall > 下面配置信息我加上了allowMultiQueries=true,并且注释掉了 wall 配置,这样就可以了 ``` spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Shanghai&useAffectedRows=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: root password: 123456 initial-size: 5 min-idle: 5 max-active: 20 max-wait: 60000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false pool-prepared-statements: true filters: stat,logback #,wall max-pool-prepared-statement-per-connection-size: 20 use-global-data-source-stat: true connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 ```
博客分类
Java (6)
Linux (6)
Docker (3)
SpringBoot (9)
微服务 (1)
Redis (13)
Mysql (2)
VMware (3)
Nginx (9)
Mybatis (2)
工具类 (3)
友情链接
权限管理系统
layui
© 2019 chenhuazhan.com All Rights Reserved 备案号:
桂ICP备17004487号-1