@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
在这里插入图片描述

  • 21
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值