What is the operation method of MyBatis-Plus inserting data in bulk?
This article will explain in detail how MyBatis-Plus inserts data in batches, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
In the spring boot+mybatis plus environment, a single insert uses the insert method that comes with BaseMapper.
Public ApiResult addAnc (Anc anc) {ApiResult result = new ApiResult (); Integer insert = ancMapper.insert (anc); if (insert < 1) {return result.failed ("publish failed, please contact the administrator");} return result.success (anc)
BaseMapper does not provide a bulk insert interface, but it does in com.baomidou.mybatisplus.service.IService
/ *
* insert (batch), this method is not suitable for Oracle *
* * @ param entityList entity object list * @ return boolean * / boolean insertBatch (List entityList); / *
* insert (batch) *
* * @ param entityList entity object list * @ param batchSize insert batches * @ return boolean * / boolean insertBatch (List entityList, int batchSize)
Using methods, define your own interface, inherit IService, and generalize to the manipulated entity class
@ Servicepublic interface WorkIService extends IService {}
Define an implementation class to implement the appeal interface
@ Servicepublic class WorkIServiceImpl extends ServiceImpl implements WorkIService {}
Where WorkMapper is the mapper of normal operation
Test bulk insert operations in the business
List entityList = new ArrayList (1000); for (int item1)