首页 > 其他分享 >MybatisPlus(八) 插件的使用~乐观锁插件(配置类篇)

MybatisPlus(八) 插件的使用~乐观锁插件(配置类篇)

时间:2023-03-12 14:11:40浏览次数:39  
标签:插件 MybatisPlus wrapper entity MybatisPlusInterceptor 类篇 new interceptor

一、Springboot 配置乐观锁插件

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //添加乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());

        return interceptor;
    }

}

二、实体类字段@Version注解

@Version
private Integer version;

说明:

  1.支持的数据类型只有:int,Integer,long,Long,Date,Timestamp,LocalDateTime

  2.整数类型下 newVersion = oldVersion + 1

  3.newVersion 会回写到 entity 中

  4.仅支持 updateById(id) 与 update(entity, wrapper) 方法

  5.在 update(entity, wrapper) 方法下, wrapper 不能复用!!!

 

标签:插件,MybatisPlus,wrapper,entity,MybatisPlusInterceptor,类篇,new,interceptor
From: https://www.cnblogs.com/Life-QX/p/17208086.html

相关文章