• 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>
    <!-- https://mvnrepository.com/artifact/p6spy/p6spy -->
    <dependency>
    <groupId>p6spy</groupId>
    <artifactId>p6spy</artifactId>
    <version>3.8.0</version>
    </dependency>
    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
    </dependency>

    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.49</version>
    <scope>test</scope>
    </dependency>
    <!-- for testing -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>
  • application.yml

    spring:
    datasource:
    driver-class-name: com.p6spy.engine.spy.P6SpyDriver
    url: jdbc:p6spy:h2:tcp://192.168.180.115:19200/~/mem/test
    username: root
    password: test
  • 实体类

    @Data
    @TableName(value = "student")
    public class Student {

    private Long id;

    private String name;

    private Integer age;

    }

    @Mapper
    public interface StudentMapper extends BaseMapper<Student> {

    void deleteAll();

    }
  • 注入器及方法

    public class DeleteAll extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    /* 执行 SQL ,动态 SQL 参考类 SqlMethod */
    String sql = "delete from " + tableInfo.getTableName();
    /* mapper 接口方法名一致 */
    String method = "deleteAll";
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
    return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
    }
    }

    @Component
    public class MySqlInjector extends DefaultSqlInjector {

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
    List<AbstractMethod> methodList = super.getMethodList(mapperClass);
    //增加自定义方法
    methodList.add(new DeleteAll());
    return methodList;
    }
    }
  • 测试类

    @SpringBootTest
    class InjectorApplicationTests {

    @Autowired(required = false)
    private StudentMapper studentMapper;

    @Test
    public void test(){
    studentMapper.deleteAll();
    }

    }
  • 测试结果

    2019-10-31 10:40:22.780  INFO 9484 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
    Consume Time:0 ms 2019-10-31 10:40:22
    Execute SQL:delete from student

SpringBoot整合MybatisPlus3.X之SQL注入器(九)的更多相关文章

  1. SpringBoot整合MybatisPlus3.X之SQL执行分析插件(十四)

    pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...

  2. SpringBoot整合MybatisPlus3.X之自定义Mapper(十)

    pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...

  3. SpringBoot整合MyBatis-Plus3.1详细教程

    作者:Sans_ juejin.im/post/5cfa6e465188254ee433bc69 一.说明 Mybatis-Plus是一个Mybatis框架的增强插件,根据官方描述,MP只做增强不做改 ...

  4. SpringBoot整合MybatisPlus3.X之乐观锁(十三)

    主要适用场景 意图: 当要更新一条记录的时候,希望这条记录没有被别人更新 乐观锁实现方式: 取出记录时,获取当前version 更新时,带上这个version 执行更新时, set version = ...

  5. SpringBoot整合MybatisPlus3.X之Wrapper(五)

    官方文档说明: 以下出现的第一个入参boolean condition表示该条件是否加入最后生成的sql中 以下代码块内的多个方法均为从上往下补全个别boolean类型的入参,默认为true 以下出现 ...

  6. SpringBoot整合MybatisPlus3.X之分页插件(四)

    注:详细请看2.X博客中,3.X直接上代码. 建议装一个MybatisX插件,可以在Mapper和Xml来回切换 pom.xml <dependencies> <dependency ...

  7. SpringBoot整合MybatisPlus3.X之逻辑删除(三)

    pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...

  8. SpringBoot整合MybatisPlus3.X之Sequence(二)

    数据库脚本 DELETE FROM user; ​ INSERT INTO user (id, name, age, email) VALUES (, , 'test1@baomidou.com'), ...

  9. SpringBoot整合Mybatisplus3.x之CRUD(一)

    pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...

随机推荐

  1. c#学习路线应该靠谱

    因为学c/c++,找不到工作.想转c#,搜索得到的学习路线 C#入门经典 C#数据库入门经典 C#高级编程 ADO.net高级编程 基础的东西搞明白之后,可以学习设计模式,C#设计模式 你是说深入的书 ...

  2. Java 基本数据类型极限值

    public static void main(String[] args){ System.out.println("Integer.MIN_VALUE = " + Intege ...

  3. Shell之命令执行的判断依据

    目录 Shell之命令执行的判断依据 参考 Shell之命令执行的判断依据

  4. JavaScript系列:函数式编程(开篇)

    前言: 上一篇介绍了 函数回调,高阶函数以及函数柯里化等高级函数应用,同时,因为正在学习JavaScript·函数式编程,想整理一下函数式编程中,对于我们日常比较有用的部分. 为什么函数式编程很重要? ...

  5. linux分析工具之vmstat详解

    一.概述 vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.首先我们查看下帮助.如下图所 ...

  6. JS时间格式CST转GMT

    转换方法:JS 时间格式CST转GMT 时区和Date:Java中的Date和时区转换

  7. typedef说明

    typedef 只对已有的类型进行别名定义,不产生新的类型: #define 只是在预处理过程对代码进行简单的替换. 类比理解: typedef  unsigned int  UINT32;  // ...

  8. redis在mac上的下载安装

    redis官网下载压缩包: 在终端进入下载后的目录,然后: 解压:tar zxvf redis-5.0.5.tar.gz 移动到:sudo mv redis-5.0.5 /usr/local 切换到: ...

  9. mapper插入时显示中文

    可能是jdbc url需要加characterEncoding=utf-8,例 jdbc:mysql://localhost:3306/smbms?characterEncoding=utf8

  10. 多线程下的wait为什么可以不需要notify

    多线程下的wait方法就像我无处安放的青春,胡乱来,感觉没有一点套路.wait后不需要notify仍可以继续执行.所以我决定看看到底咋回事..... 先结合join方法了解一下. join方法是可以等 ...