• 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>

    <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>
  • 配置文件

    @Configuration
    public class MybatisPlusConfig {


    @Bean
    public SqlExplainInterceptor sqlExplainInterceptor(){
    SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
    List<ISqlParser> sqlParserList = new ArrayList<>();
    sqlParserList.add(new BlockAttackSqlParser());
    sqlExplainInterceptor.setSqlParserList(sqlParserList);
    return sqlExplainInterceptor;
    }


    }
  • 实体类

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

    private Long id;

    private String name;

    private Integer age;

    }

    @Mapper
    public interface StudentMapper extends BaseMapper<Student> {


    }
  • application.yml

    spring:
    datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:tcp://192.168.180.115:19200/~/mem/test
    username: root
    password: test

    mybatis-plus:
    global-config:
    db-config:
    id-type: id_worker
    capital-mode: true
    configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  • 数据库SQL

-- noinspection SqlNoDataSourceInspectionForFile

DROP TABLE IF EXISTS student;

CREATE TABLE student
(
id BIGINT (20) NOT NULL COMMENT '主键ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
age INT (11) NULL DEFAULT NULL COMMENT '年龄',
PRIMARY KEY (id)
);
  • 测试类

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class AnalysisApplicationTests {

    private static final Logger LOGGER = LoggerFactory.getLogger(AnalysisApplicationTests.class);

    @Autowired(required = false)
    private StudentMapper studentMapper;

    @Test
    public void test(){
    studentMapper.selectList(new QueryWrapper<>());
    studentMapper.deleteById(1L);
    Student student = new Student();
    student.setName("test_update");
    studentMapper.insert(new Student(1L,"test",12));
    studentMapper.update(student,new QueryWrapper<Student>().eq("id",1L));
    try {
    studentMapper.update(new Student(),new QueryWrapper<>());
    }catch (MyBatisSystemException e){
    }
    try {
    studentMapper.delete(new QueryWrapper<>());
    }catch (MyBatisSystemException e){

    }
    Assert.notEmpty(studentMapper.selectList(new QueryWrapper<>()),"数据都被删掉了.(┬_┬)");
    }

    }
     
  • 测试结果

    JDBC Connection [HikariProxyConnection@356338363 wrapping conn0: url=jdbc:h2:tcp://192.168.180.115:19200/~/mem/test user=ROOT] will not be managed by Spring
    ==> Preparing: SELECT ID,NAME,AGE FROM student
    ==> Parameters:
    <== Total: 0
    Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@73ba6fe6]
    Creating a new SqlSession
    SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d96d872] was not registered for synchronization because synchronization is not active
    JDBC Connection [HikariProxyConnection@897801829 wrapping conn0: url=jdbc:h2:tcp://192.168.180.115:19200/~/mem/test user=ROOT] will not be managed by Spring
    ==> Preparing: DELETE FROM student WHERE ID=?
    ==> Parameters: 1(Long)
    <== Updates: 0
    Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d96d872]
    Creating a new SqlSession
    SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@49cf9028] was not registered for synchronization because synchronization is not active
    JDBC Connection [HikariProxyConnection@1876259196 wrapping conn0: url=jdbc:h2:tcp://192.168.180.115:19200/~/mem/test user=ROOT] will not be managed by Spring
    ==> Preparing: INSERT INTO student ( ID, NAME, AGE ) VALUES ( ?, ?, ? )
    ==> Parameters: 1(Long), test(String), 12(Integer)
    <== Updates: 1
    Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@49cf9028]
    Creating a new SqlSession
    SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@408b87aa] was not registered for synchronization because synchronization is not active
    JDBC Connection [HikariProxyConnection@527247308 wrapping conn0: url=jdbc:h2:tcp://192.168.180.115:19200/~/mem/test user=ROOT] will not be managed by Spring
    ==> Preparing: UPDATE student SET NAME=? WHERE (id = ?)
    ==> Parameters: test_update(String), 1(Long)
    <== Updates: 1

SpringBoot整合MybatisPlus3.X之SQL执行分析插件(十四)的更多相关文章

  1. SpringBoot整合MybatisPlus3.X之SQL注入器(九)

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

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

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

  3. MySQL 的性能(上篇)—— SQL 执行分析

    简介 文中内容均为阅读前辈的文章所整理而来,参考文章已在最后全指明 本文分为上下两篇: 上篇:MySQL 的 SQL 执行分析 下篇:MySQL 性能优化 后端开发必然会接触到数据库,数据层的优劣会影 ...

  4. MP实战系列(十五)之执行分析插件

    SQL 执行分析拦截器[ 目前只支持 MYSQL-5.6.3 以上版本 ],作用是分析 处理 DELETE UPDATE 语句, 防止小白或者恶意 delete update 全表操作! 这里我引用M ...

  5. Linux内核分析 - 网络[十四]:IP选项

    Linux内核分析 - 网络[十四]:IP选项 标签: linux内核网络structsocketdst 2012-04-25 17:14 5639人阅读 评论(1) 收藏 举报  分类: 内核协议栈 ...

  6. mysql数据库SQL执行分析,优化前必备分析

    概述 一般我们在对mysql数据库做优化,肯定需要对慢sql去做分析才能开始优化,那么有什么分析的方法呢?下面通过对sql执行时间和执行情况来做分析. 一.SQL 执行时间分析 通过找到执行时间长的 ...

  7. C#语言和SQL Server第十三 十四章笔记

    十三章  使用ADO.NET访问数据库 十四章使用ADO.NET查询和操作数据库 十三章:                                                       ...

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

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

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

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

随机推荐

  1. 4.7 if else-if

    c#中的if else-if if else-if  中最后的"else":如果用户输入的不等于上面的else if(xxx)表达式,则输出这行代码. **不参与运算的数值不用转换 ...

  2. ajax跨域访问数据

    通过json发送和接受数据,数据以json的格式在服务器端和前台进行传递,什么是json数据?这里就不进行详细阐述,轻自行百度解决. 在html5 中利用ajax 异步请求时,会遇到跨域的问题,如果域 ...

  3. JavaScript实现各种排序算法

    前言:本文主要是用JavaScript实现数据结构中的各种排序算法,例如:插入排序.希尔排序.合并排序等. 冒泡排序 function bubbleSort(arr) { console.time(& ...

  4. 多线程基础(主要内容转载于https://segmentfault.com/a/1190000014428190)

    进程作为资源分配的基本单位 线程作为资源调度的基本单位,是程序的执行单元,执行路径(单线程:一条执行路径,多线程:多条执行路径).是程序使用CPU的最基本单位. 线程有3个基本状态: 执行.就绪.阻塞 ...

  5. Spring Boot 2.X(五):MyBatis 多数据源配置

    前言 MyBatis 多数据源配置,最近在项目建设中,需要在原有系统上扩展一个新的业务模块,特意将数据库分库,以便减少复杂度.本文直接以简单的代码示例,如何对 MyBatis 多数据源配置. 准备 创 ...

  6. Web高性能动画及渲染原理(1)CSS动画和JS动画

    目录 一. CSS动画 和 JS动画 1.1 CSS动画 1.2 JS动画 1.3 小结 二. 使用Velocity.js实现动画 示例代码托管在:http://www.github.com/dash ...

  7. java集合类之ArrayList详解

    一.ArrayList源码分析 1.全局变量 (1)默认容量(主要是通过无参构造函数创建ArrayList时第一次add执行扩容操作时指定的elementData的数组容量为10) private s ...

  8. BZOJ 4597: [Shoi2016]随机序列

    4597: [Shoi2016]随机序列 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 255  Solved: 174[Submit][Status ...

  9. bugku 各种·绕过

    点开是一段PHP的代码,先来审计一波代码. 发现将uname和passwd用sha1进行了加密,那么我们只要绕过这个函数构造相等就可以了. 可以使这两个值sha1的值相等,但他们本身的值又不等.(想详 ...

  10. Mac上Charles抓包iOS的https请求

    介绍一款抓包工具,一般我在windows下使用Fiddler抓包,Fiddler使用教程这里就不讲了,重点介绍使用mac时的抓包工具----Charles. 进入官网 :Charles官网地址官网下载 ...