首页 > 其他分享 >Parameter 'MP_OPTLOCK_VERSION_ORIGINAL' not found. Available parameters are [param1, et]

Parameter 'MP_OPTLOCK_VERSION_ORIGINAL' not found. Available parameters are [param1, et]

时间:2022-08-26 15:57:33浏览次数:62  
标签:Available return OPTLOCK parameters MybatisPlusInterceptor user interceptor publ

我用的是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();
    }
}

也可以这么写

/**

  • mybatisplus分页插件和乐观锁

  • @data 2021/9/14
    **/
    @Configuration
    public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

     MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
     interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
     return interceptor;
    

    }
    }

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

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

标签:Available,return,OPTLOCK,parameters,MybatisPlusInterceptor,user,interceptor,publ
From: https://www.cnblogs.com/fuqian/p/16627782.html

相关文章