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

MybatisPlus實現(xiàn)insertBatchSomeColumn進行批量增加

 更新時間:2023年03月17日 09:52:03   作者:林卓淇  
本文主要介紹了MybatisPlus實現(xiàn)insertBatchSomeColumn進行批量增加,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1、引入相關(guān)依賴

? ? ? ? <!--mybatis-plus啟動器-->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.baomidou</groupId>
? ? ? ? ? ? <artifactId>mybatis-plus-boot-starter</artifactId>
? ? ? ? ? ? <version>3.5.1</version>
? ? ? ? </dependency>
? ? ? ? ? ? ? ? <!--mybatis-plus擴展插件依賴-->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.baomidou</groupId>
? ? ? ? ? ? <artifactId>mybatis-plus-extension</artifactId>
? ? ? ? ? ? <version>3.5.1</version>
? ? ? ? </dependency>

2、編寫sql注入器

package com.linmain.mysql.config;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;

import java.util.List;

/**
?* @Author linzhuoqi
?* @Date 2023/3/10
?* @Eamil 1580752420@qq.com
?* @Version
?* @Description ? ?自定義的sql注入器,插入了批量插入的方法
?*/
public class EasySqlInjector extends DefaultSqlInjector {
? ? @Override
? ? public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {

? ? ? ? // 注意:此SQL注入器繼承了DefaultSqlInjector(默認(rèn)注入器),調(diào)用了DefaultSqlInjector的getMethodList方法,保留了mybatis-plus的自帶方法
? ? ? ? List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
? ? ? ? //增加了一個批量插入的方法
? ? ? ? methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
? ? ? ? return methodList;
? ? }
}

3、在mybatisPlus的配置類中注入插件

@Configuration
public class MyBatisPlusConfig {
?
? ? @Bean
? ? public MybatisPlusInterceptor mybatisPlusInterceptor(){
? ? ? ? MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
? ? ? ? //添加分頁插件
? ? ? ? interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
? ? ? ? //添加樂觀鎖插件
? ? ? ? interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
? ? ? ? return interceptor;
? ? }
?
? ? @Bean
? ? public EasySqlInjector easySqlInjector() {
? ? ? ? return new EasySqlInjector();
? ? }
?
}

4、編寫dao層接口

package com.linmain.column.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linmain.column.pojo.entity.ColTag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
?* 專欄標(biāo)簽(ColTag)表數(shù)據(jù)庫訪問層
?*
?* @Author linzhuoqi
?* @Date 2023-03-02 20:44:38
?* @Eamil 1580752420@qq.com
?* @Version
?* @Description
?*/
@Mapper
public interface ColTagDao extends BaseMapper<ColTag> {
? ? /**
? ? ?* 批量插入 僅適用于mysql
? ? ?*
? ? ?* @param entityList 實體列表
? ? ?* @return 影響行數(shù)
? ? ?*/
? ? Integer insertBatchSomeColumn(Collection<ColTag> entityList);
}

5、最后

進行正常的使用即可

colTagDao.insertBatchSomeColumn(colTags);

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

相關(guān)文章

  • 將本地的jar包打到Maven的倉庫中實例

    將本地的jar包打到Maven的倉庫中實例

    下面小編就為大家分享一篇將本地的jar包打到Maven的倉庫中實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • JavaMail實現(xiàn)簡單郵件發(fā)送

    JavaMail實現(xiàn)簡單郵件發(fā)送

    這篇文章主要為大家詳細(xì)介紹了JavaMail實現(xiàn)簡單郵件發(fā)送,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Spring動態(tài)加載bean后調(diào)用實現(xiàn)方法解析

    Spring動態(tài)加載bean后調(diào)用實現(xiàn)方法解析

    這篇文章主要介紹了Spring動態(tài)加載bean后調(diào)用實現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • Java后端接入微信小程序登錄功能(登錄流程)

    Java后端接入微信小程序登錄功能(登錄流程)

    這篇文章主要介紹了Java后端接入微信小程序登錄功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • SpringBoot3中token攔截器鏈的設(shè)計與實現(xiàn)步驟

    SpringBoot3中token攔截器鏈的設(shè)計與實現(xiàn)步驟

    本文介紹了spring boot后端服務(wù)開發(fā)中有關(guān)如何設(shè)計攔截器的思路,文中通過代碼示例和圖文講解的非常詳細(xì),具有一定的參考價值,需要的朋友可以參考下
    2024-03-03
  • Java解決No enclosing instance of type PrintListFromTailToHead is accessible問題的兩種方案

    Java解決No enclosing instance of type PrintListFromTailToHead

    這篇文章主要介紹了Java解決No enclosing instance of type PrintListFromTailToHead is accessible問題的兩種方案的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • 淺談JVM系列之從匯編角度分析NullCheck

    淺談JVM系列之從匯編角度分析NullCheck

    在virtual call中執(zhí)行nullcheck的時候,如果已經(jīng)知道傳遞的參數(shù)是非空的。JIT會對代碼進行優(yōu)化嗎?本文將詳細(xì)介紹JVM系列之從匯編角度分析NullCheck。
    2021-06-06
  • Java中的分布式事務(wù)Seata詳解

    Java中的分布式事務(wù)Seata詳解

    這篇文章主要介紹了Java中的分布式事務(wù)Seata詳解,Seata 是一款開源的分布式事務(wù)解決方案,致力于提供高性能和簡單易用的分布式事務(wù)服務(wù),Seata 將為用戶提供了 AT、TCC、SAGA 和 XA 事務(wù)模式,為用戶打造一站式的分布式解決方案,需要的朋友可以參考下
    2023-08-08
  • java 解析user-agent 信息

    java 解析user-agent 信息

    這篇文章主要介紹了java 解析http user-agent的信息的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • MyBatis-Plus實現(xiàn)多數(shù)據(jù)源的示例代碼

    MyBatis-Plus實現(xiàn)多數(shù)據(jù)源的示例代碼

    這篇文章主要介紹了MyBatis-Plus實現(xiàn)多數(shù)據(jù)源的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評論