Mybatis批量修改時(shí)出現(xiàn)報(bào)錯(cuò)問題解決方案
批量修改代碼如下
<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批量修改時(shí)報(bào)錯(cuò),錯(cuò)誤為sql語句錯(cuò)誤:
開始檢查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>
感覺并沒有錯(cuò)誤,把錯(cuò)誤語句復(fù)制到Navicat上能正常運(yùn)行,于是網(wǎng)上查找了一下需要在url語句中添加allowMultiQueries=true,添加后成功運(yùn)行。
Mysql中allowMultiQueries=true作用:
1.可以在sql語句后攜帶分號(hào),實(shí)現(xiàn)多語句執(zhí)行。
2.可以執(zhí)行批處理,同時(shí)發(fā)出多個(gè)SQL語句
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 傳甲骨文將增加對(duì)MySQL投資與微軟競(jìng)爭(zhēng)2. MySQL Community Server 5.1.493. Oracle與Access表之間的導(dǎo)入和導(dǎo)出4. MySQL插入數(shù)據(jù)時(shí),如果記錄不存在則insert,如果存在則update5. Mysql故障排除:Starting MySQL. ERROR! Manager of pid-file quit without updating file6. 講解SQL Server數(shù)據(jù)庫備份的多種方式7. Mybatis #foreach中相同的變量名導(dǎo)致值覆蓋的問題解決8. 如何安裝MySQL 壓縮包9. 學(xué)好Oracle的六條總結(jié)10. 全面解析DB2 V9.1復(fù)制技術(shù)的新特性和改進(jìn)
