使用foreach批量更新数据报无效字符错误
改动前
<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>
后台执行的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>
后台执行的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;
正常执行~~~~~~~~
mybatis报“无效字符”的错的原因
mybatis报ora-00911: 无效字符。
原因是
在mapper配置中有“;”
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论