mybatis-plus 乐观锁 Parameter ‘MP_OPTLOCK_VERSION_ORIGINAL‘ not found.

我用的是3.0.5的mybatis-plus版本 但是我用3.4.0的OptimisticLockerInterceptor 会显示已过时但是还能用

按照乐观锁的步骤

模型上加属性

//    @TableField(fill = FieldFill.INSERT)
    @Version
    private int version;

然后数据库加上

对应的配置文件一定要有@Configuration注解别拼错 少了这一步就会报参数没找到 Parameter 'MP_OPTLOCK_VERSION_ORIGINAL' not found. Available parameters are [param1, et]

//开启事务
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }
}

最后更新的时候需要先查询再根据查询出来的进行更新

    @RequestMapping("/update")
    public int update(){
        //乐观锁需要先查询再插入
        User user=userServer.selectById(31);
        user.setUsername("test");
        user.setAge(123);
        return userServer.updateById(user);
    }

 


版权声明:本文为qq_37975021原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。