1.void saveContentData(List<Map<String, String>> list) throws Exception;
//保存数据内容
List<Map<String, String>> contentList = new ArrayList<>();
Map<String, String> content = null;
//获取数据(JSONArray里是JSONObject)
JSONArray contentArray = (JSONArray) pd.get("content");
//把Json转为String
for (Object data : contentArray) {
content =new HashMap<>();
content.put("bid", pd.get("bid") + "");
content.put("content", JSON.toJSONString(data, SerializerFeature.QuoteFieldNames));
contentList.add(content);
}
<insert id="saveContentData" parameterType="List">
INSERT INTO `dynamic_excel_content`(bid, content) VALUES
<foreach collection="list" index="index" item="item" separator=",">
<foreach collection="item" index="key" item="value" open="(" close=")" separator=",">
#{value}
</foreach>
</foreach>
</insert>
2.void updateBatch(List list) throws Exception;
批量更新数据
//保存数据内容
List<Map<String, String>> contentList = new ArrayList<>();
List<PageData> list = new ArrayList<>();
Map<String, String> content = null;
PageData p = null;
//获取数据(JSONArray里是JSONObject)
JSONArray contentArray = (JSONArray) pd.get("content");
//判断之前是否有数据
Integer[] ids = dynamicExcelContentMapper.getDynamicExcelContentIds(pd);
if (ids.length > 0) {
for (int i = 0, len = contentArray.size(); i < len; i++) {
p = new PageData();
p.put("dynamic_contentid", ids[i]);
p.put("content", JSON.toJSONString(contentArray.getJSONObject(i), SerializerFeature.QuoteFieldNames));
list.add(p);
}
dynamicExcelContentMapper.updateBatch(list);
}
<update id="updateBatch" parameterType="list">
update dynamic_excel_content
<trim prefix="set" suffixOverrides=",">
<trim prefix="content =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.content !=null and item.content != ''">
when dynamic_contentid = #{item.dynamic_contentid} then #{item.content}
</if>
</foreach>
</trim>
</trim>
where dynamic_contentid in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.dynamic_contentid}
</foreach>
</update>
update dynamic_excel_content set content =case
when dynamic_contentid = 'ff' then '22'
when dynamic_contentid = 'ff' then '33'
end
where dynamic_contentid in (143, 146)