Mapper icon indicating copy to clipboard operation
Mapper copied to clipboard

MyBatis批量提交是否有最佳实践

Open koudaiDemon opened this issue 3 years ago • 1 comments

我看到作者在之前的回复中,有文档地址,不过评论中关于session是否需要手动关闭以及是否把这个方法直接放入BaseService有一些讨论,所以希望作者能回复一下!

MyBatis 批量提交 - BATCH:https://blog.csdn.net/isea533/article/details/80922305

Originally posted by @abel533 in https://github.com/abel533/Mapper/issues/286#issuecomment-409816017

koudaiDemon avatar Aug 02 '21 10:08 koudaiDemon

文章已更新内容。

2021-8-25 补充说明

回复中很多人在问,要不要手动关闭 sqlSession,文中说的不严谨,不完全正确。

  1. 当你添加 @Transactional 注解时,Spring 会自动帮你关闭连接,因此不需要手动关闭。

  2. 当没有使用该注解时,必须手动关闭连接。

大多数连接池的的连接关闭操作实际上是释放连接,释放后就可以让其他请求使用,如果所有连接都被占用而没有释放时,就会抛出异常。

abel533 avatar Aug 25 '21 02:08 abel533