Mybatis批量修改時出現(xiàn)報錯問題解決方案
批量修改代碼如下
<update parameterType='java.util.List'> <foreach collection='list' item='item' index='index' separator=';'> UPDATE VST_HOTEL_REAL_TIME_PRICE <set><if test='item.realTimePrice1 != null'> REAL_TIME_PRICE1 = #{item.realTimePrice1},</if><if test='item.realTimePrice2 != null'> REAL_TIME_PRICE2 = #{item.realTimePrice2},</if><if test='item.realTimeRemain1 != null'> REAL_TIME_REMAIN1 = #{item.realTimeRemain1},</if><if test='item.realTimeRemain2 != null'> REAL_TIME_REMAIN2 = #{item.realTimeRemain2},</if>UPDATE_TIME = NOW() </set> WHERE PRODUCT_ID = ${item.productId} </foreach> </update>
今天在使用mybatis批量修改時報錯,錯誤為sql語句錯誤:
開始檢查xml中代碼:
<update parameterType='list'> <foreach collection='list' item='type' index='index' separator=';'> UPDATE t_type <set><if test='type.name != null'> t_name = #{type.name}</if> </set> where t_id = #{type.id} </foreach> </update>
感覺并沒有錯誤,把錯誤語句復制到Navicat上能正常運行,于是網(wǎng)上查找了一下需要在url語句中添加allowMultiQueries=true,添加后成功運行。
Mysql中allowMultiQueries=true作用:
1.可以在sql語句后攜帶分號,實現(xiàn)多語句執(zhí)行。
2.可以執(zhí)行批處理,同時發(fā)出多個SQL語句
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Access數(shù)據(jù)庫安全的幾個問題2. mysql-bin.000001文件的來源及處理方法3. mysql命令行客戶端結(jié)果分頁瀏覽4. Windwos下MySQL 64位壓縮包的安裝方法學習記錄5. mysql啟動時報錯 ERROR! Manager of pid-file quit without6. ACCESS轉(zhuǎn)SQL數(shù)據(jù)庫相關(guān)的幾個技能7. 數(shù)據(jù)庫相關(guān)的幾個技能:ACCESS轉(zhuǎn)SQL8. MYSQL數(shù)據(jù)庫存文本轉(zhuǎn)存數(shù)據(jù)庫問題9. MySQL中InnoDB和MyISAM類型的差別10. MySQL中 concat函數(shù)的使用

網(wǎng)公網(wǎng)安備