在springboot+MP 项目中使用乐观锁遇到的问题
使用乐观锁的东西我都配置了
第一种问题(找不到字段,直接测试失败)
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'MP_OPTLOCK_VERSION_ORIGINAL' not found. Available parameters are [param1, et]
第二种问题: (version字段为null导致无法更新数据,测试成功但是因为Version字段为null无法满足条件)
[main] [cn.itcast.mp.mapper.UserMapper.updateById]-[DEBUG] ==> Preparing: UPDATE tb_user SET age=?, version=? WHERE id=? AND version=?
[main] [cn.itcast.mp.mapper.UserMapper.updateById]-[DEBUG] ==> Parameters: 1000(Integer), 1(Integer), 2(Long), null
Consume Time:1 ms 2023-06-09 23:08:25:355
[main] [cn.itcast.mp.mapper.UserMapper.updateById]-[DEBUG] <== Updates: 0
Execute SQL:UPDATE tb_user SET age=1000, version=1 WHERE id=2 AND version=NULL
求达答案
不知道你这个问题是否已经解决, 如果还没有解决的话:需要在mybatis-plus拦截器的配置中添加OptimisticLockerInnerInterceptor()
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mpi = new MybatisPlusInterceptor();
//添加分页拦截器
mpi.addInnerInterceptor(new PaginationInnerInterceptor());
//添加乐观锁拦截器
mpi.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return mpi;
}
配置mybatis-plus乐观锁的步骤
1、先在数据库表中添加version字段
2、在实体类中定义version字段,并使用@Version注解标记
3、在mybatis-plus拦截器中添加OptimisticLockerInnerInterceptor()乐观锁拦截器
回答部分参考、引用ChatGpt以便为您提供更准确的答案:
针对您的问题,解决PyCharm的Python Console在无操作后自动断开连接的问题,可以考虑以下方法:
~/.ssh/config
)中添加以下行来启用KeepAlive:Host *
ServerAliveInterval 60
这将每60秒发送一个KeepAlive信号到服务器,防止连接超时断开。请根据您的具体情况选择适合您的解决方案,以解决PyCharm的Python Console连接超时的问题,提高工作效率。