Mybatis批量更新SQL報錯☞解決辦法
批量更新語句(XML對映)如下:
<!--批量更新使用者表資料-->
<update id ="updateBatch" parameterType="java.util.List">
<foreach collection ="users" item="user" index= "index" close=";" separator =";">
update user
<set>
name = #{user.name}
</set>
<where>
id =#{user.id}
</where>
</foreach>
</update>
Insomnia測試介面【測了兩條資料】,結果報錯:
後臺檢視異常資訊如下:
更奇怪的是,批量操作一條資料是OK的:
哪裡有問題呢?
原來,Mybatis對映檔案中的sql語句預設是不支援以" ; " 結尾的,也就是不支援多條sql語句的執行
但是在SQL編輯器中執行多條sql語句的時候是可以以分號結尾的,如:
解決辦法:
在application.properties配置文中的資料來源url後面新增一個引數
&allowMultiQueries=true 【允許sql語句中有多個insert或者update語句 == 支援sql批量操作】
原來的:
#注意SpringBoot2.0 這裡的資料來源url是: jdbc-url 而不是 url
spring.datasource.jdbc-url=jdbc\:mysql\://localhost\:3306/slave?useUnicode\=true&autoReconnect=true&useSSL=false&characterEncoding\=utf-8&useSSL=true
現在的:
#注意SpringBoot2.0 這裡的資料來源url是: jdbc-url 而不是 url
spring.datasource.jdbc-url=jdbc\:mysql\://localhost\:3306/slave?useUnicode\=true&autoReconnect=true&useSSL=false&characterEncoding\=utf-8&useSSL=true&allowMultiQueries=true
重啟專案後,測試:
相關文章
- sysctl -P 報錯解決辦法
- mybatis報錯解決MyBatis
- cnpm link 報錯解決辦法NPM
- git報錯400的解決辦法Git
- 執行Docker命令報錯解決辦法Docker
- isNaN("abc")編譯報錯解決辦法NaN編譯
- mybatis update並非所有欄位需要更新的解決辦法MyBatis
- 安裝ionic 報錯 安裝canvas報錯 解決辦法Canvas
- Could not resolve host: 'localhost 報錯解決辦法localhost
- 安裝sysbench過程報錯,解決辦法
- 建庫時EM報錯的解決辦法
- IOConsole Updater 報錯解決辦法
- kali更新源數字簽名錯誤解決辦法
- This function has none of DETEMINISTIC,NO SQL錯誤解決辦法FunctionNoneSQL
- mybatis-plugin is not activated yet解決辦法MyBatisPlugin
- myeclipse專案報錯終極解決辦法Eclipse
- sphinx :undefined reference to `libiconv' 報錯解決辦法Undefined
- VMware 啟動報錯 "Failed to lock the file"解決辦法AI
- oracle 10g emctl 報錯的解決辦法Oracle 10g
- man出錯解決辦法
- mybatis 批量新增insert、更新update詳解MyBatis
- ClamAV無法更新錯誤解決
- Jsp Unescaped xml character報錯的解決辦法JSXML
- Docker Hello World容器執行報錯的解決辦法Docker
- vue報錯:the template root disallows ‘v-for‘ directives解決辦法Vue
- Laravel Mix - 執行 NPM install 報錯解決辦法LaravelNPM
- 客戶系統報錯:soft lockup的解決辦法
- ORA-38706&ORA-38707報錯解決辦法
- VirtualBox-4.3.0啟動報錯及解決辦法
- Perl CPAN安裝報錯CPAN::Modulelist的解決辦法
- 批量更新時無法觸發事件的解決方法事件
- SAP錯誤提示解決辦法
- Mybatis批量更新三種方式MyBatis
- 關於npm install安裝報錯的解決辦法NPM
- Maven下載jar包慢,pom報錯的解決辦法MavenJAR
- SVN報錯“Failed to run the WC DB work queue associated with”解決辦法AI
- 關於Chrome報錯 ERR_NAME_NOT_RESOLVED 解決辦法Chrome
- PHP報錯“Parseerror:syntaxerror,unexpectedT_VARIABLE”的解決辦法PHPError