Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the operation method of MyBatis-Plus inserting data in bulk?

Shulou Source: shulou.com Published: 2022-06-03 10:01:13 11月15日 Update

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)

Tags: Methods data entities interfaces content objects articles more environment knowledge articles not bad not big business advantages methods of use differences batches quantities are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple NVidia Shulou Information MySQL