注意where条件字段需要索引
// 引入template
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
public void saveAndUpdate(List list)throws Exception {
// 当前会话开启批量模式
SqlSession sqlSession =sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
// 从会话中获取到mapper
CustomerInsightMapper mapper = sqlSession.getMapper(CustomerInsightMapper.class);
try {
for (CustomerInsightInfo info : list) {
mapper.saveAndUpdate(info);
}
//提交
sqlSession.commit();
sqlSession.clearCache();
}catch (Exception e) {
sqlSession.rollback();
throw new Exception(e);
}finally {
sqlSession.close();
}
}