| @Configuration |
| public class MybatisPlusOptLockerConfig { |
| |
| @Bean |
| public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); |
| return interceptor; |
| } |
| } |
| @Data |
| public class User { |
| |
| @TableId(value = "id", type = IdType.AUTO) |
| private Long id; |
| private String name; |
| private Integer age; |
| private String email; |
| @Version |
| private Integer version; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| @Order(4) |
| @Test |
| public void testUpdateByEntitySucc() { |
| QueryWrapper<User> ew = new QueryWrapper<>(); |
| ew.eq("version", 1); |
| long count = userMapper.selectCount(ew); |
| |
| User entity = new User(); |
| entity.setAge(28); |
| entity.setVersion(1); |
| |
| |
| Assertions.assertEquals(count, userMapper.update(entity, null)); |
| ew = new QueryWrapper<>(); |
| ew.eq("version", 1); |
| |
| Assertions.assertEquals(0, userMapper.selectCount(ew).intValue()); |
| ew = new QueryWrapper<>(); |
| ew.eq("version", 2); |
| |
| |
| System.out.println(count + "--->" + userMapper.selectCount(ew).intValue()); |
| } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术