使用SqlSessionTemplate的方式对实体信息批量保存
@Value("#{rdsSqlSession.getMapper(T(*.*.*.*.*.*.*.*PoMapper))}")
private *Mapper *PoMapper;
@Resource(name = "rdsSqlSession")
private SqlSessionTemplate sqlSessionTemplate;
public void insert(List<*Info> infoList) {
List<*InfoPo> poList = infoList.stream().map(*Convert::convert2Po).collect(Collectors.toList());
SqlSession batchSession = null;
try{
batchSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH);
batchSession.insert("*.*.*.*.*.*.*.*PoMapper.batchInsert", poList);
batchSession.commit();
batchSession.clearCache();
} catch (Exception e) {
logger.error("*Dal insert error, infoList:{}, e", infoList, e);
throw new *Exception(*ErrorCodeConst.*);
} finally {
if (batchSession != null) {
batchSession.close();
}
}
}