乐观锁
说明
save时 version 字段会自动填充0,update(实体类)、delete(实体类)自动会增加version条件:where version=?
示例
实体类
java
@Data
@Table
public class SysUser {
@TableId
private Integer id;
private String userName;
private String password;
private Integer roleId;
private LocalDateTime createTime;
@Version
private Integer version;
}
Mapper
继承 MybatisMapper 即可
java
public interface SysUserMapper extends MybatisMapper<SysUser> {
}
如何使用
java
@Service
public class Test{
@Autowired
private SysUserMapper sysUserMapper;
public void demo() {
SysUser sysUser=new SysUser();
sysUserMapper.save(sysUser);
}
}
save时 version 字段会自动填充0,update(实体类)、delete(实体类)自动会增加version条件:where version=?
前往@Version 查看