Saul's blog Saul's blog
首页
后端
分布式
前端
更多
分类
标签
归档
友情链接
关于
GitHub (opens new window)

Saul.J.Wu

立身之本,不在高低。
首页
后端
分布式
前端
更多
分类
标签
归档
友情链接
关于
GitHub (opens new window)
  • 面试题

  • 博客搭建

  • 部署相关

  • 填坑

    • Mybatis-Plus
    • mysql安装后,没有默认密码
    • mybatis-plus逻辑删除
      • 步骤1:
      • 步骤2:
    • springboot 2.3.x 版本无法引用 javax.validation.constraints. 下的 @NotNull 注解
    • SpringBoot的全局异常处理类不生效
    • 谷粒商城下载的sql中,pms_attr,缺少value_type字段
    • IP address could not be resolved Name or service not known错误解决
    • 在linux服务器上安装jdk
    • yum安装maven
    • git提交多个远程仓库
    • SpringBoot多模块依赖yml不生效
    • Error launching IDEA
    • Linux查看端口占用并关闭程序
    • GitCommitId开发生产环境长度不一致
    • 记一次MySql UTF-8问题
  • Python

  • 其他

  • 收藏夹

  • 友情链接
  • 更多
  • 填坑
SaulJWu
2020-08-27

mybatis-plus逻辑删除

官方文档

https://baomidou.com/guide/logic-delete.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%EF%BC%9A (opens new window)

# 步骤1:

配置com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig

  • 例: application.yml
mybatis-plus:
  global-config:
    db-config:
      logic-delete-field: flag  # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
      logic-delete-value: 1 # 逻辑已删除值(默认为 1)
      logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
1
2
3
4
5
6

# 步骤2:

实体类字段上加上@TableLogic注解

@TableLogic
private Integer deleted;
1
2

如果某张表,逻辑删除跟该微服务的全局逻辑删除配置相反,还可以自定义。

源码:

/*
 * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.baomidou.mybatisplus.annotation;

import java.lang.annotation.*;

/**
 * 表字段逻辑处理注解(逻辑删除)
 *
 * @author hubin
 * @since 2017-09-09
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
public @interface TableLogic {

    /**
     * 默认逻辑未删除值(该值可无、会自动获取全局配置)
     */
    String value() default "";

    /**
     * 默认逻辑删除值(该值可无、会自动获取全局配置)
     */
    String delval() default "";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

也就是说,问只需要在字段上指明已删除和未删除的值

/**
  * 是否显示[0-不显示,1显示] 
  */
@TableLogic(delval = "0",value = "1")
private Integer showStatus;
1
2
3
4
5
帮我改善此页面 (opens new window)
#mybatis-plus
上次更新: 2021/02/16, 12:29:08
mysql安装后,没有默认密码
springboot 2.3.x 版本无法引用 javax.validation.constraints. 下的 @NotNull 注解

← mysql安装后,没有默认密码 springboot 2.3.x 版本无法引用 javax.validation.constraints. 下的 @NotNull 注解→

最近更新
01
zabbix学习笔记二
02-28
02
zabbix学习笔记一
02-10
03
Linux访问不了github
12-08
更多文章>
Theme by Vdoing | Copyright © 2020-2022 Saul.J.Wu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式