• 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. 同时支持EF+Dapper的混合仓储,助你快速搭建数据访问层

    背景 17年开始,公司开始向DotNet Core转型,面对ORM工具的选型,当时围绕Dapper和EF发生了激烈的讨论.项目团队更加关注快速交付,他们主张使用EF这种能快速开发的ORM工具:而在线业 ...

  2. Redis AOF 持久化详解

    Redis 是一种内存数据库,将数据保存在内存中,读写效率要比传统的将数据保存在磁盘上的数据库要快很多.但是一旦进程退出,Redis 的数据就会丢失. 为了解决这个问题,Redis 提供了 RDB 和 ...

  3. Flutter学习笔记(29)--Flutter如何与native进行通信

    如需转载,请注明出处:Flutter学习笔记(29)--Flutter如何与native进行通信 前言:在我们开发Flutter项目的时候,难免会遇到需要调用native api或者是其他的情况,这时 ...

  4. Angular: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as ‘standalone’ in ngModelOptions.

    在Angular中,动态生成的Html控件,如果没有name属性并且在ts中要操作Model的内容.就会引发如题的错误. 解决方案两个: 加上name的属性 设置ngModelOptions   [n ...

  5. 从零开始的 phpstorm+wamp 组合下的debug环境搭建(纯小白向)

    本文主要是为了帮自己记住每次重装系统后需要干点啥,如果能帮到你,烦请给个好评 环境说明: 1. windows10 64bit 2. wampservers 3.0.6(x86) apache2.4. ...

  6. Java读源码之ThreadLocal

    前言 JDK版本: 1.8 之前在看Thread源码时候看到这么一个属性 ThreadLocal.ThreadLocalMap threadLocals = null; ThreadLocal实现的是 ...

  7. c++ exercises

    1.定义个数组并初始化,然后将数组倒置,并显示倒置前和倒置后的结果. #include <iostream> #include <stdio.h> using namespac ...

  8. Docker 配置国内镜像

    前言 当我们使用Docker pull 拉取镜像时,有时候因网络问题,导致获取镜像报错,如下 :Error response from daemon:Get https://registry-1.co ...

  9. Hive 官方手册翻译 -- Hive DML(数据操纵语言)

    由 Confluence Administrator创建, 最终由 Lars Francke修改于 八月 15, 2018 原文链接 https://cwiki.apache.org/confluen ...

  10. SVM面试知识点总结

    1. SVM 原理 SVM 是一种二类分类模型.它的基本思想是在特征空间中寻找间隔最大的分离超平面使数据得到高效的二分类,具体来讲,有三种情况(不加核函数的话就是个线性模型,加了之后才会升级为一个非线 ...