最近在做一个前后端分离的小项目,需要删除用户表的用户,但是用户再别的表做了外键,所以只能做成逻辑删除,一通百度查资料后得以实现:
1、用户实体类
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
41
42
43
44
45
46
|
package com.sie.demo.entity; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.sql.Timestamp; //@Data:作用于类上,是以下注解的集合:@ToString @EqualsAndHashCode @Getter @Setter @RequiredArgsConstructor @Data @AllArgsConstructor @NoArgsConstructor @TableName ( "Users" ) public class Users implements Serializable { private static final long serialVersionUID = 30L; //mabatis-plus:数据库的字段命名方式为使用下划线连接,对应的实体类应该是驼峰命名方式 String userName; String password; String name; int status; int sex; @JSONField (format = "yyyy-MM-dd HH:mm:ss" ) Timestamp createTime; @JSONField (format = "yyyy-MM-dd HH:mm:ss" ) Timestamp updateTime; String email; String note; @TableId ( "user_id" ) long userId; String phoneNumber; @TableLogic //这个标签用来标识这是个用来伪删除的字段 @TableField ( "IS_DELETE" ) int isDelete; public Users(String userName, String password) { this .userName = userName; this .password = password; } } |
2、yml配置
1
2
3
4
5
|
mybatis-plus: global-config: db-config: logic-delete-value: 1 # 逻辑已删除值(默认为 1) logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) |
3、service层,
1
2
3
4
5
6
7
8
9
|
@Override /** * 删除用户 */ public Integer deleteUserByIds(String[] userSelected) { Wrapper wrapper = new QueryWrapper(); List userIds = Arrays.asList(userSelected); return userMapper.deleteBatchIds(userIds); } |
4、controller层
1
2
3
4
5
6
7
8
9
|
@DeleteMapping ( "delete" ) public RetResult<PageUserVo> deleteUserByIds(String[] ids){ Integer isDelete = userService.deleteUserByIds(ids); if (isDelete != 0 ){ return RetResponse.makeRsp( 200 , "删除成功" ); } else { return RetResponse.makeRsp( 500 , "删除失败" ); } } |
5、运行后控制台的sql语句直接就是update了
完毕!
springboot+oracle+mybatis-plus实现分页
到此这篇关于springboot+mybatis-plus+oracle实现逻辑删除的文章就介绍到这了,更多相关springboot+mybatis-plus+oracle 逻辑删除内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/weixin_46108919/article/details/119336252