• pom.xml

    1. <dependencies>
    2. <dependency>
    3. <groupId>org.springframework.boot</groupId>
    4. <artifactId>spring-boot-starter</artifactId>
    5. </dependency>
    6. <dependency>
    7. <groupId>com.baomidou</groupId>
    8. <artifactId>mybatis-plus-boot-starter</artifactId>
    9. <version>3.2.0</version>
    10. </dependency>
    11. <dependency>
    12. <groupId>org.projectlombok</groupId>
    13. <artifactId>lombok</artifactId>
    14. </dependency>
    15. <dependency>
    16. <groupId>com.h2database</groupId>
    17. <artifactId>h2</artifactId>
    18. <scope>runtime</scope>
    19. </dependency>

    20. <dependency>
    21. <groupId>com.alibaba</groupId>
    22. <artifactId>fastjson</artifactId>
    23. <version>1.2.49</version>
    24. <scope>test</scope>
    25. </dependency>
    26. <!-- for testing -->
    27. <dependency>
    28. <groupId>org.springframework.boot</groupId>
    29. <artifactId>spring-boot-starter-test</artifactId>
    30. <scope>test</scope>
    31. </dependency>
    32. </dependencies>
  • 配置文件

    1. @Configuration
    2. public class MybatisPlusConfig {


    3. @Bean
    4. public SqlExplainInterceptor sqlExplainInterceptor(){
    5. SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
    6. List<ISqlParser> sqlParserList = new ArrayList<>();
    7. sqlParserList.add(new BlockAttackSqlParser());
    8. sqlExplainInterceptor.setSqlParserList(sqlParserList);
    9. return sqlExplainInterceptor;
    10. }


    11. }
  • 实体类

    1. @Data
    2. @TableName(value = "student")
    3. @NoArgsConstructor
    4. @AllArgsConstructor
    5. public class Student {

    6. private Long id;

    7. private String name;

    8. private Integer age;

    9. }

    10. @Mapper
    11. public interface StudentMapper extends BaseMapper<Student> {


    12. }
  • application.yml

    1. spring:
    2. datasource:
    3. driver-class-name: org.h2.Driver
    4. url: jdbc:h2:tcp://192.168.180.115:19200/~/mem/test
    5. username: root
    6. password: test

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

  1. -- noinspection SqlNoDataSourceInspectionForFile

  2. DROP TABLE IF EXISTS student;

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

    1. @RunWith(SpringRunner.class)
    2. @SpringBootTest
    3. public class AnalysisApplicationTests {

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

    5. @Autowired(required = false)
    6. private StudentMapper studentMapper;

    7. @Test
    8. public void test(){
    9. studentMapper.selectList(new QueryWrapper<>());
    10. studentMapper.deleteById(1L);
    11. Student student = new Student();
    12. student.setName("test_update");
    13. studentMapper.insert(new Student(1L,"test",12));
    14. studentMapper.update(student,new QueryWrapper<Student>().eq("id",1L));
    15. try {
    16. studentMapper.update(new Student(),new QueryWrapper<>());
    17. }catch (MyBatisSystemException e){
    18. }
    19. try {
    20. studentMapper.delete(new QueryWrapper<>());
    21. }catch (MyBatisSystemException e){

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

    25. }
    1.  
  • 测试结果

    1. 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
    2. ==> Preparing: SELECT ID,NAME,AGE FROM student
    3. ==> Parameters:
    4. <== Total: 0
    5. Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@73ba6fe6]
    6. Creating a new SqlSession
    7. SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d96d872] was not registered for synchronization because synchronization is not active
    8. 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
    9. ==> Preparing: DELETE FROM student WHERE ID=?
    10. ==> Parameters: 1(Long)
    11. <== Updates: 0
    12. Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d96d872]
    13. Creating a new SqlSession
    14. SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@49cf9028] was not registered for synchronization because synchronization is not active
    15. 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
    16. ==> Preparing: INSERT INTO student ( ID, NAME, AGE ) VALUES ( ?, ?, ? )
    17. ==> Parameters: 1(Long), test(String), 12(Integer)
    18. <== Updates: 1
    19. Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@49cf9028]
    20. Creating a new SqlSession
    21. SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@408b87aa] was not registered for synchronization because synchronization is not active
    22. 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
    23. ==> Preparing: UPDATE student SET NAME=? WHERE (id = ?)
    24. ==> Parameters: test_update(String), 1(Long)
    25. <== 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. Exceptionless 5.0.0 本地Docker快速部署介绍

    在之前我有专门写两篇文章介绍过Exceptionless这款开源日志项目的使用和部署,但是当时是基于4.1.0版本(2017年的release),时隔两年多Exceptionless也推出了5.0.0 ...

  2. Spring 梳理-webApplicationContext 与servletContext

    1.WebApplicationContext的研究 ApplicationContext是spring的核心,Context通常解释为上下文环境,用“容器”来表述更容易理解一些,Applicatio ...

  3. Spring 梳理-运行时动态注入bean

    动态注入的方法 使用占位符 使用Spring表达式

  4. 只要听说过电脑的人都能看懂的网上pdf全书获取项目

    作者:周奇 最近我要获取<概统>的教材自学防挂科(线代已死),于是我看到 htt链ps:/链/max链.book接118接.com接/html/2018/0407/160495927.sh ...

  5. 【Java】 生成32位随机字符编号

    /** * 生成32位编码 * @return string */ public static String getUUID(){ String uuid = UUID.randomUUID().to ...

  6. Linux下格式化恢复USB启动优盘

    问题描述:优盘制作成启动盘安装操作系统,但是后边使用时发现无法格式化,提示 This partition cannot be modified because it contains a partit ...

  7. springboot使用百度富文本UEditor遇到的问题一览(springboot controller中request.getInputStream无法读取)

    先吐槽一下UEditor作为一个前端的js类库,非要把4种后端的代码给出来,而实际生产中用的框架不同,其代码并不具有适应性.(通常类似其它项目仅仅是给出数据交互的规范.格式,后端实现就可以自由定制) ...

  8. C#的FTP服务器源代码

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. Windows 8.1硬盘安装Ubuntu 14.04双系统参考教程及多硬盘注意事项

    本文来自:http://www.linuxidc.com/Linux/2015-08/122140.htm,此处仅做收藏. Windows 8.1硬盘安装Ubuntu 14.04双系统参考教程及多硬盘 ...

  10. go 学习笔记之解读什么是defer延迟函数

    Go 语言中有个 defer 关键字,常用于实现延迟函数来保证关键代码的最终执行,常言道: "未雨绸缪方可有备无患". 延迟函数就是这么一种机制,无论程序是正常返回还是异常报错,只 ...