mybatis plus 乐观锁
*****************************************
相关注解
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface Version {
}
支持的数据类型:int 、 Integer、long、Long、Date、Timestamp、LocalDateTime
支持的方法:updataById(id),update(Entity entity,Wrapper wrapper)
操作示例:
pojo
@ApiModel(value="Student对象", description="")
public class Student extends Model<Student> {
private static final long serialVersionUID=1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
private Integer age;
@Version
private Integer version;
。。。。
}
**************************************************
controller层
@RestController
@RequestMapping("/student")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("/save")
public String save(){
Student student=new Student();
student.setName("瓜田李下");
student.setAge(23);
studentService.save(student);
return "success";
}
@RequestMapping("/update")
public Student update(){
Student student=studentService.getById(1);
student.setName("海贼王");
studentService.updateById(student);
return studentService.getById(student.getId());
}
}
插入、更新测试
来源:https://blog.csdn.net/weixin_43931625/article/details/100917104