欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatisPlus自定義批量新增的實現(xiàn)代碼

 更新時間:2020年11月05日 10:42:29   作者:敲出快樂  
這篇文章主要介紹了mybatisPlus自定義批量新增的實現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

mybatisPlus底層的新增方法是一條一條的新增的,今天自定義批量新增方法。
創(chuàng)建自定義數(shù)據(jù)方法注入類

/**
 * @Description: EasySqlInjector 自定義數(shù)據(jù)方法注入
 * @Author WangYejian
 * @Date: 2020/11/4 14:34
 */
public class EasySqlInjector extends DefaultSqlInjector {

  @Override
  public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
    //防止父類方法不可用
    List<AbstractMethod> methods= super.getMethodList(mapperClass);
    methods.add(new InsertBatchSomeColumn());
    return methods;
  }
}

在mybatisplus配置文件MybatisPlusConfig加入自定義

@Bean
  public EasySqlInjector easySqlInjector() {
    return new EasySqlInjector();
  }

創(chuàng)建EasyBaseMapper 擴(kuò)展通用 Mapper

package com.cgmcomm.mallplus.basic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.Collection;

/**
 * @Description: EasyBaseMapper 擴(kuò)展通用 Mapper,支持?jǐn)?shù)據(jù)批量插入
 * @Author WangYejian
 * @Date: 2020/10/15 18:57
 */
public interface EasyBaseMapper<T> extends BaseMapper<T> {

  /**
   * 批量插入 僅適用于mysql
   *
   * @param entityList 實體列表
   * @return 影響行數(shù)
   */
  Integer insertBatchSomeColumn(Collection<T> entityList);
}
**
 * 定義業(yè)務(wù)mapper接口,繼承剛剛擴(kuò)展的EasyBaseMapper
 *
 * @author 天開易想
 */
@Mapper
public interface TestMapper extends EasyBaseMapper<Test> {
}

/**
 * 業(yè)務(wù)實現(xiàn)類接口,即可引用
 */
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService {

  @Override
  public Integer testBatch(Collection<Test> testList) {
    return baseMapper.insertBatchSomeColumn(testList);
  }

到此這篇關(guān)于mybatisPlus自定義批量新增的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)mybatisPlus自定義批量新增內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論