SpringBoot整合MybatisPlus3.X之逻辑删除(三)
pom.xml
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.2.0</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>runtime</scope>
- </dependency>
-
- <!-- for testing -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <dependencies>
application.yml
- # DataSource Config
- spring:
- datasource:
- driver-class-name: org.h2.Driver
- url: jdbc:h2:tcp://192.168.180.115:19200/~/mem/test
- username: root
- password: test
-
- # Logger Config
- logging:
- level:
- com.mp.logicdelete: debug
- mybatis-plus:
- # 扫描 mapper.xml
- mapper-locations: classpath:/mapper/*Mapper.xml
- global-config:
- banner: false
- db-config:
- logic-delete-value: 1 #默认值1
- logic-not-delete-value: 0 #默认值0
- # DataSource Config
启动类
- @SpringBootApplication
- @MapperScan("com.mq.logicdelete.mapper")
- public class LogicdeleteApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(LogicdeleteApplication.class, args);
- }
-
- }
-
- @SpringBootApplication
实体类
- @Data
- public class User {
- private Integer id;
- private String name;
- private Integer age;
- private String email;
- @TableLogic
- private Integer isDelete;
- }
- @Data
dao层
- public interface UserMapper extends BaseMapper<User> {
-
- }
-
- public interface UserMapper extends BaseMapper<User> {
数据库脚本
- DELETE FROM user;
-
- INSERT INTO user (id, name, age, email) VALUES
- (1, 'Jone', 18, 'test1@baomidou.com'),
- (2, 'Jack', 20, 'test2@baomidou.com'),
- (3, 'Tom', 28, 'test3@baomidou.com'),
- (4, 'Sandy', 21, 'test4@baomidou.com'),
- (5, 'Billie', 24, 'test5@baomidou.com');
-
- DROP TABLE IF EXISTS user;
-
- CREATE TABLE user
- (
- id BIGINT(20) NOT NULL COMMENT '主键ID',
- name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
- age INT(11) NULL DEFAULT NULL COMMENT '年龄',
- email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
- is_delete INT(11) NOT NULL DEFAULT 0 COMMENT '是否删除',
- PRIMARY KEY (id)
- );
- DELETE FROM user;
测试类
- @RunWith(SpringRunner.class)
- @SpringBootTest
- class LogicdeleteApplicationTests {
-
- @Resource
- private UserMapper userMapper;
-
- @Test
- public void testLogicDeleteById() {
- userMapper.deleteById(1);
- }
-
- @Test
- public void testLogicDeleteBatchIds() {
- userMapper.deleteBatchIds(Arrays.asList(1, 2, 3));
- }
-
- @Test
- public void testLogicDelete() {
- userMapper.delete(new QueryWrapper<User>().eq("age", 2));
- }
-
- }
- @RunWith(SpringRunner.class)
测试结果,运行部分测试代码(其实底层的是update语句)
SpringBoot整合MybatisPlus3.X之逻辑删除(三)的更多相关文章
- springboot整合elasticJob实战(纯代码开发三种任务类型用法)以及分片系统,事件追踪详解
一 springboot整合 介绍就不多说了,只有这个框架是当当网开源的,支持分布式调度,分布式系统中非常合适(两个服务同时跑不会重复,并且可灵活配置分开分批处理数据,贼方便)! 这里主要还是用到zo ...
- SpringBoot整合MyBatis-Plus3.1详细教程
作者:Sans_ juejin.im/post/5cfa6e465188254ee433bc69 一.说明 Mybatis-Plus是一个Mybatis框架的增强插件,根据官方描述,MP只做增强不做改 ...
- springboot整合mybatis增删改查(三):mybatis逆向工程
上一篇已经把项目基本框架完善,接下来就是利用Mybatis Generator逆向工程进行mybatis的整合. 我们在创建项目开始的时候已经勾选web,mybatis,sql等,但是这些依赖还是不够 ...
- springboot整合es客户端操作elasticsearch(三)
继续上个随笔: 那么我们只需要修改controller中文件就可以完成相关操作 本次主要是对文档得操作: 更新文档: package com.cxy.elasticsearch.controller; ...
- SpringBoot整合MybatisPlus3.X之SQL执行分析插件(十四)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MybatisPlus3.X之乐观锁(十三)
主要适用场景 意图: 当要更新一条记录的时候,希望这条记录没有被别人更新 乐观锁实现方式: 取出记录时,获取当前version 更新时,带上这个version 执行更新时, set version = ...
- SpringBoot整合MybatisPlus3.X之自定义Mapper(十)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MybatisPlus3.X之SQL注入器(九)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MybatisPlus3.X之Wrapper(五)
官方文档说明: 以下出现的第一个入参boolean condition表示该条件是否加入最后生成的sql中 以下代码块内的多个方法均为从上往下补全个别boolean类型的入参,默认为true 以下出现 ...
随机推荐
- python爬虫添加请求头和请求主体
添加头部信息有两种方法 1.通过添加urllib.request.Request中的headers参数 #先把要用到的信息放到一个字典中 headers = {} headers['User-Agen ...
- dedecms新增联动类别后的使用方法
近期用织梦的联动类别,后台明明可以直接新增联动类别,但是你直接调用是绝对调用不出来的............. 折腾了好几天终于全部解决,回忆下过程以便日后再遇到的时候参考. 第一步:先按照常规的在后 ...
- latex转word公式 java (latextoword,latex_word,latex2word,latex_omml)
latex_word 主要目的: 给大家分享一个我的原创作品:latex转为word公式(omml)工具 [java] 此工具主要用于将含有latex公式的文本下载成word时,将latex转 ...
- java多态的实现原理(JVM调用过程)(综合多篇文章,参考见文末)
一个对象变量可以指示多种实际类型的现象称为多态 允许不同类的对象对同一消息做出响应.方法的重载.类的覆盖正体现了多态. 1.多态的机制 1.1 本质上多态分两种 1.编译时多态(又称静态多态) 2.运 ...
- Kafka 学习笔记之 架构
Kafka的概念: 1. AMQP协议 Advanced Message Queuing Protocol (高级消息队列协议) The Advanced Message Queuing Protoc ...
- Senparc.Weixin.MP SDK 微信公众平台开发教程(二十二):在 .NET Core 2.0/3.0 中使用 MessageHandler 中间件
概述 在 <Senparc.Weixin.MP SDK 微信公众平台开发教程(六):了解MessageHandler> 中我们已经了解了 MessageHandler 的运行原理和使用方法 ...
- MIPI CSI2-TX接口基于FPGA实现
MIPI CSI2-TX用途: 跟海思的3559A芯片进行图像数据传输: MIPI CSI2-TX接口特性: xilinx 7系列芯片最大支持1.25Gbps: 最大支持lanes数量为4: 支持的图 ...
- ES6——新增数据结构Set与Map的用法
ES6 提供了新的数据结构 Set以及Map,下面我们来一一讲解. 一.Set 特性 似于数组,但它的一大特性就是所有元素都是唯一的,没有重复. 我们可以利用这一唯一特性进行数组的去重工作. 1.单一 ...
- 【源码解析】自动配置的这些细节不知道,别说你会 springboot
spring-boot 相对于 spring,很重要的一个特点就是自动配置,使约定大于配置思想成功落地.xxx-spring-boot-starter 一系列引导器能够开箱即用,或者只需要很少的配置( ...
- BZOJ 1965 [AHOI2005]洗牌
题目描述 为了表彰小联为Samuel星球的探险所做出的贡献,小联被邀请参加Samuel星球近距离载人探险活动. 由于Samuel星球相当遥远,科学家们要在飞船中度过相当长的一段时间,小联提议用扑克牌打 ...