Mybatis
作者:互联网
SqlSession
SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);//第二个参数为是否自动提交,为true则执行一次sql就提交,若为false则表示开启事务
TbTestMapper tbTestMapper = sqlSession.getMapper(TbTestMapper.class);
try {
for (int i = 1; i <= 10; i++) {
TbTest tbTest = new TbTest();
tbTest.setId(i);
tbTest.setUpdateTime(new Date());
tbTestMapper.updateByPrimaryKeySelective(tableField);
}
sqlSession.commit();
sqlSession.clearCache();
} catch (Exception e) {
sqlSession.rollback();
} finally {
sqlSession.close();
}
注意SqlSession批量新增时,无法返回新增后记录的主键。
标签:false,SqlSession,sqlSession,TbTestMapper,提交,Mybatis,主键 来源: https://www.cnblogs.com/yuking28/p/16490169.html