Mybatis使用foreach批量更新數(shù)據(jù)報無效字符錯誤問題
更新時間:2024年08月19日 10:44:31 作者:MiracleSang
這篇文章主要介紹了Mybatis使用foreach批量更新數(shù)據(jù)報無效字符錯誤問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
使用foreach批量更新數(shù)據(jù)報無效字符錯誤
改動前
<update id="updateByECBoxIdBatch" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close=";" separator=";"> update EC_ENTRUST_BOX set REALMONEY = #{item.money,jdbcType=DECIMAL} where BOX_ID = #{item.boxId,jdbcType=VARCHAR} and ENTRUST_MONEY_ID = #{item.ecEntrustMoneyId,jdbcType=VARCHAR} </foreach> </update>
后臺執(zhí)行的SQL:
update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ; update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ; update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ;
報錯:無效字符
改動后:(加了begin,end)
<update id="updateByECBoxIdBatch" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";"> update EC_ENTRUST_BOX set REALMONEY = #{item.money,jdbcType=DECIMAL} where BOX_ID = #{item.boxId,jdbcType=VARCHAR} and ENTRUST_MONEY_ID = #{item.ecEntrustMoneyId,jdbcType=VARCHAR} </foreach> </update>
后臺執(zhí)行的SQL:
begin update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ; update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ; update EC_ENTRUST_BOX set REALMONEY = ? where BOX_ID = ? and ENTRUST_MONEY_ID = ? ;end;
正常執(zhí)行~~~~~~~~
Mybatis報“無效字符”的錯的原因
mybatis報ORA-00911: 無效字符。
原因是
在mapper配置中有“;”
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Java List集合返回值去掉中括號(''[ ]'')的操作
這篇文章主要介紹了Java List集合返回值去掉中括號('[ ]')的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08解析Neatbeans(常見錯誤) build-impl.xml:305: Compile failed
本篇文章是對Neatbeans(常見錯誤) build-impl.xml:305: Compile failed的解決方法進行了詳細的分析介紹,需要的朋友參考下2013-07-07