84669인 학습
152542인 학습
20005인 학습
5487인 학습
7821인 학습
359900인 학습
3350인 학습
180660인 학습
48569인 학습
18603인 학습
40936인 학습
1549인 학습
1183인 학습
32909인 학습
认证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>
你 好 ,解决 没有 ,我的也遇到了
此问 关闭 题主没有找到任何答案 靠升级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>
你 好 ,解决 没有 ,我的也遇到了