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>
你 好 ,解决 没有 ,我的也遇到了