jQuery火箭图标返回顶部代码

mybatis 操作 mysql 大批量插入,数据分页处理

/**
* 大批量插入,数据分页处理
*
* @param tableName 临时表名称
* @param mapHead 临时表属性 Map,key = 临时表字段属性, value = 具体值。此处 value 没有使用
* @param mapList 临时表的大批量数据
*/
private void pageDate(String tableName, Map<String, Object> mapHead, List<HashMap<String, Object>> mapList) {

//测试(大批量插入):条数-耗时:6300-2s,16800-5s24000-7s 67300-18s
for (int i = 0, j = 0, amount = 3000; i < mapList.size(); i += amount) {
j = i + amount;
//amount可取值3000/5000/10000/。。。测看大批量效果。
try {
if (j < mapList.size()) {
insertBatchList(tableName, mapHead, mapList.subList(i, mapList.size()));
} else {
insertBatchList(tableName, mapHead, mapList.subList(i, mapList.size()));
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}

}

 
/**
* 批量插入数据
*
* @param tableName 临时表名称
* @param mapHead 临时表属性 Map,key = 临时表字段属性, value = 具体值。此处 value 没有使用
* @param list 临时表分页后的批量数据
*/
private void insertBatchList(String tableName, Map<String, Object> mapHead, List<HashMap<String, Object>> list) {
HashMap<String, Object> map = new HashMap<>();
map.put("tableName", tableName);
map.put("mapHead", mapHead);
map.put("list", list);
reportAllSqlMapper.insertBatchTableListDynamic(map);
}


mybatis mapper 层接口
/**
* 批量插入数据
* @param map
*/
void insertBatchTableListDynamic(@Param("map")HashMap<String,Object> map);


mybatis xml
<insert id="insertBatchTableListDynamic" parameterType="java.util.HashMap">
insert into
${map.tableName}
(
<foreach collection="map.mapHead" index="key" item="value"
separator=",">
`${key}`
</foreach>
)
values
<foreach collection="map.list" item="line" separator=",">
(
<foreach collection="line" index="key" item="value"
separator=",">
#{value}
</foreach>
)
</foreach>
</insert>


 
posted @ 2021-12-01 15:07  天下没有收费的bug  阅读(495)  评论(0编辑  收藏  举报