求教MyBatis批量插入参数是List<Map<String,Object>gt;的问题
1个回答
展开全部
dao实现文件中函数:
@Override
public int insertContentList(
List<PubFieldContentEntity> list) {
Map<String, Object> params = createMap();
params.put("list", list);
return this.insert("insertContentList", params);
}
对应的mapper.xml文件中
<!-- 批量插入 -->
<insert id="insertContentList" useGeneratedKeys="true" keyProperty="id">
<![CDATA[
insert into tableContent(pubId,integrant,ownContentName,dateLine,pubFieldContentName,suffix,modifyTime,deleteTime,compareType,pubContentIndex,multiple,isInput,pubFieldTitle) values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.pubId},#{item.integrant},#{item.ownContentName},unix_timestamp(),#{item.pubFieldContentName},#{item.suffix},unix_timestamp(),#{item.deleteTime},#{item.compareType},#{item.pubContentIndex},#{item.multiple},#{item.isInput},#{item.pubFieldTitle})
</foreach>
]]>
</insert>
@Override
public int insertContentList(
List<PubFieldContentEntity> list) {
Map<String, Object> params = createMap();
params.put("list", list);
return this.insert("insertContentList", params);
}
对应的mapper.xml文件中
<!-- 批量插入 -->
<insert id="insertContentList" useGeneratedKeys="true" keyProperty="id">
<![CDATA[
insert into tableContent(pubId,integrant,ownContentName,dateLine,pubFieldContentName,suffix,modifyTime,deleteTime,compareType,pubContentIndex,multiple,isInput,pubFieldTitle) values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.pubId},#{item.integrant},#{item.ownContentName},unix_timestamp(),#{item.pubFieldContentName},#{item.suffix},unix_timestamp(),#{item.deleteTime},#{item.compareType},#{item.pubContentIndex},#{item.multiple},#{item.isInput},#{item.pubFieldTitle})
</foreach>
]]>
</insert>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询