@TableLogic注解

@TableLogic注解表示逻辑删除

1、在实体类中属性加上@TableLogic注解,表示该字段是逻辑删除字段。
2、增加注解后调用BaseMapper的deleteById(id)或者IService的removeById(id),是逻辑删除。如果没有增加该注解,是真删除。
3、@TableLogic注解参数
 value = “未删除的值,默认值为0”
 delval = “删除后的值,默认值为1”
 如果不设置,就使用默认值

@TableLogic(value="原值",delval="改值")

4、 当使用了@TableLogic注解,调用update方法修改该字段的值是不会将该字段放入修改字段中,而是在条件字段中where条件后。
5、demo
SysUser的删除标识位字段增加了注解@TableLogic

@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "SysUser对象", description = "系统用户")
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "id")
    private Long id;

    @ApiModelProperty(value = "用户名", required = true)
    @NotBlank(groups = {Insert.class, Update.class}, message = "用户名不能为空")
    private String userName;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "密码")
    @NotBlank(groups = {Insert.class}, message = "密码不能为空")
    private String password;

    @ApiModelProperty(value = "盐值")
    @Null(groups = {Insert.class, Update.class}, message = "盐值不用传")
    private String salt;

    @ApiModelProperty(value = "手机号码", required = true)
    @Phone(groups = {Insert.class, Update.class})
    private String phone;

    @ApiModelProperty(value = "邮箱")
    @Email(groups = {Insert.class, Update.class})
    private String email;

    @ApiModelProperty(value = "性别,0:女,1:男,默认1")
    private Integer sex;

    @ApiModelProperty(value = "头像")
    private String head;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "状态,0:禁用,1:启用,2:锁定")
    @Dict(name="com.sinosoft.springbootplus.system.enums.UserStatus",dataSource = Dict.Type.ENUM,target = "stateName")
    private String state;
    @TableField(exist = false)
    @ApiModelProperty(value = "用户状态")
    private String stateName;

    @ApiModelProperty(value = "部门id", required = true)
    @NotNull(groups = {Insert.class, Update.class}, message = "部门id不能为空")
    private Long departmentId;

    @ApiModelProperty(value = "角色ids,用逗号隔开", required = true)
    @NotBlank(groups = {Insert.class, Update.class}, message = "角色id不能为空")
    @TableField(exist = false)
    private String roleId;

    @ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除")
    @Null(groups = {Insert.class, Update.class}, message = "逻辑删除不用传")
    @TableLogic
    @TableField(select = false)
    private Integer deleted;

    @ApiModelProperty(value = "版本")
    @Null(groups = {Insert.class, Update.class}, message = "版本不用传")
    @Version
    private Integer version;

    @ApiModelProperty(value = "创建时间")
    @Null(groups = {Insert.class, Update.class}, message = "创建时间不用传")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @Null(groups = {Insert.class, Update.class}, message = "修改时间不用传")
    @TableField(fill = FieldFill.UPDATE)
    private Date updateTime;

    @ApiModelProperty(value = "租户Id")
    private Long tenantId;
}

查询查询时,没有拼删除标识位的条件,但是sql还是自动加上了where delete =0
@TableLogic注解_第1张图片

你可能感兴趣的:(java,spring,mybatis)