扫码关注官方订阅号
认证0级讲师
此问 关闭 题主没有找到任何答案 靠升级mybatis版本后解决此问题
在list和数组中,index是元素的序号,在map中,index是元素的key,该参数可选。
index
<insert id="batchInsert"> insert into personal_tag(type, tag, create_time, open_account_id) values <foreach collection="list" item="item" index="index" separator=","> (#{item.type,jdbcType=INTEGER}, #{item.tag,jdbcType=VARCHAR}, #{item.createTme,jdbcType=TIMESTAMP}, #{item.openAccountId,jdbcType=BIGINT}) </foreach>ON DUPLICATE KEY UPDATE tag=tag
ON DUPLICATE KEY UPDATE tag=tag把这一句改为ON DUPLICATE KEY UPDATE tag=#{item.tag}
BindingException,那么一定是Mybatis遍历你Collections的时候,有个对象取不到item属性,也许你放了一个null对象,请检查你的List<Object>
<insert id="batchInsert" parameterType="java.util.List"> insert into personal_tag(type, tag, create_time, open_account_id) values <foreach collection="list" item="item" separator=","> (#{item.type,jdbcType=INTEGER}, #{item.tag,jdbcType=VARCHAR}, #{item.createTme,jdbcType=TIMESTAMP}, #{item.openAccountId,jdbcType=BIGINT}) </foreach>ON DUPLICATE KEY UPDATE tag=tag </insert> 在insert标签加参数类型呢 修改下参数别名呢,还有接口的参数名,下面是我们之前的项目里的 void addRiskItemBatch(@Param("lstItem")List<FastRiskItemInfo> lstItem); <!-- 批量添加条款 --> <insert id="addRiskItemBatch" useGeneratedKeys="true" parameterType="java.util.List"> <selectKey resultType="long" keyProperty="id" order="AFTER"> SELECT LAST_INSERT_ID() </selectKey> insert into fast_risk_item_info (query_id, risk_item_id, item_no, item_name, item_price, status, create_time) values <foreach collection="lstItem" item="item" index="index" separator="," > (#{item.queryId,jdbcType=INTEGER}, #{item.riskItemId,jdbcType=INTEGER}, #{item.itemNo,jdbcType=VARCHAR}, #{item.itemName,jdbcType=VARCHAR}, # {item.itemPrice,jdbcType=DECIMAL}, #{item.status,jdbcType=INTEGER}, #{item.createTime,jdbcType=VARCHAR}) </foreach> </insert>
你 好 ,解决 没有 ,我的也遇到了
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
此问 关闭 题主没有找到任何答案 靠升级mybatis版本后解决此问题
在list和数组中,
index是元素的序号,在map中,index是元素的key,该参数可选。ON DUPLICATE KEY UPDATE tag=tag
把这一句改为
ON DUPLICATE KEY UPDATE tag=#{item.tag}
BindingException,那么一定是Mybatis遍历你Collections的时候,有个对象取不到item属性,也许你放了一个null对象,请检查你的List<Object>
你 好 ,解决 没有 ,我的也遇到了