性能分析插件

我们在平时的开发中,会遇到一些慢sql,测试,druid

MP(MyBatisPlus)也提供性能分析插件,如果超过这个时间就停止

不过官方在3.2版本的时候取消了,原因如下

条件构造器

十分重要: Wrapper

我们写一些复杂查询的时候

首先创建一个测试类

@SpringBootTest
public class MyBatisPlusWrapperTest {
@Autowired
private AirMapper airMapper;
}
// 查询一些用户:
// 查询一下pm10为22且monitoring_station不为空的用户,
@Test
public void test1(){
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.isNotNull("monitoring_station")//数据库中的名字,而不是实体类中的名字
.eq("pm10",22);
List<Air> airList = airMapper.selectList(wrapper);//可以对比下map的查询
airList.forEach(System.out::println);//循环遍历输出
}
//查询单个用户
@Test
public void test2() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.eq("id",222);
airMapper.selectOne(wrapper); }
//Butween And
//查询pm25在40-60之间的用户和数量
@Test
public void test3() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.between("pm25",40,60);//区间
airMapper.selectList(wrapper).forEach(System.out::println);
System.out.println(airMapper.selectCount(wrapper));//查询结果数
}
//模糊查询
//查询monitor_station中带"站"的,切不带"哈"的
@Test
public void test4() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.like("monitoring_station","站").notLike("monitoring_station","哈");
airMapper.selectList(wrapper).forEach(System.out::println);
}
//查询以哈开头切以站结尾的 哈% %站
@Test
public void test5() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.likeLeft("monitoring_station","站").likeRight("monitoring_station","哈");
airMapper.selectList(wrapper).forEach(System.out::println);
}
//嵌入sql查询
@Test
public void test6() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.inSql("district_id","select id from air where district_id = id");
airMapper.selectObjs(wrapper).forEach(System.out::println);
}
//多表查询
//通过id进行排序
@Test
public void test7() {
QueryWrapper<Air> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("id");
airMapper.selectList(wrapper).forEach(System.out::println);
}

代码生成器

导入依赖

在3.0.3版本以后代码生成器需要手动添加依赖

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.2</version>
</dependency>

根据前端的模板引擎导入相应依赖(我没写前端页面就随便导入了一个velocity的)记住一定要加入其中一个,否则会报错

具体配置代码

package com.cloudcentury.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import java.util.ArrayList; /**
* ClassName:臭狗屎王溥松
* Package:com.cloudcentury.mybatis
*
* @date:2020/8/7 10:22
* @author:2628710400@qq.com Description:
*/
public class CodeAuto {
public static void main(String[] args) {
//需要构建一个代码自动生成器对象 AutoGenerator ag = new AutoGenerator();//代码生辰器对象
//配置执行策略
//1.全局配置
GlobalConfig gc = new GlobalConfig();//全局配置对象
String property = System.getProperty("user.dir");//获取项目名称
System.out.println(property);
gc.setOutputDir(property+"/src/main/java");//设置代码存放路径
gc.setAuthor("臭狗屎");//设置作者
gc.setOpen(false);//设置是否打开资源管理器(生成完毕后)
gc.setFileOverride(false);//是否覆盖代码
gc.setServiceName("%sService");//去掉Service的I前缀
gc.setIdType(IdType.AUTO);//设置id自动生成类型
gc.setDateType(DateType.ONLY_DATE);//日期时间,仅仅时间
gc.setSwagger2(false);//是否设置swagger
ag.setGlobalConfig(gc);//将全局配置放到里面 //设置数据源
DataSourceConfig desc = new DataSourceConfig();//数据源配置对象
//设置url
desc.setUrl("jdbc:mysql://localhost:3306/air?characterEncoding=utf8&serverTimezone=GMT");
desc.setDriverName("com.mysql.cj.jdbc.Driver");//设置驱动
desc.setUsername("root");//设置用户名
desc.setPassword("12345");//设置密码
desc.setDbType(DbType.MYSQL);//设置数据库类型
ag.setDataSource(desc);//将数据源放到里面 //包的配置
//说白了就是说需要生成那些包,叫什么
PackageConfig pc = new PackageConfig();//包配置对象
pc.setModuleName("com");//模块名字
pc.setParent("com.cloudcentury");//父模块名字
pc.setEntity("entity");//Entity包的名字
pc.setMapper("mapper");//mapper包的名字
pc.setService("service");//service包的名字
pc.setController("controller");//controller包的名字
ag.setPackageInfo(pc);//将包的配置放到里面 //策略配置
StrategyConfig sc = new StrategyConfig();
sc.setInclude("air","district"); //设置要映射的表名,这个一定要设置的
sc.setNaming(NamingStrategy.underline_to_camel);//设置名字下划线转大写
sc.setColumnNaming(NamingStrategy.underline_to_camel);//设置列明下划线转大写
sc.setEntityLombokModel(true);//自动生成lombok
sc.setLogicDeleteFieldName("deleted");//逻辑删除的名字 //自动填充配置
TableFill monitor_time = new TableFill("monitor_time", FieldFill.INSERT);//执行插入是更新时间
TableFill last_modify_time = new TableFill("last_modify_time", FieldFill.INSERT);//执行更新时执行的操作
ArrayList<TableFill> tableFills = new ArrayList<>();//创建一个List
tableFills.add(monitor_time);
tableFills.add(last_modify_time);
sc.setTableFillList(tableFills);//这里只有这一个用list的方法
sc.setVersionFieldName("version"); //乐观锁的配置
sc.setRestControllerStyle(true);//开启rest式的驼峰命名
sc.setControllerMappingHyphenStyle(true);//下划线命名:localhost:8080/hello_id_2
ag.setStrategy(sc);//策略配置对象
ag.execute();//执行
}
}

MyBatisPlus性能分析插件,条件构造器,代码自动生成器详解的更多相关文章

  1. MySQL性能分析、及调优工具使用详解

    本文汇总了MySQL DBA日常工作中用到的些工具,方便初学者,也便于自己查阅. 先介绍下基础设施(CPU.IO.网络等)检查的工具: vmstat.sar(sysstat工具包).mpstat.op ...

  2. Mybatis-plus<一> Springboot框架使用MybatisPlus代码自动生成器

    Mybatis-plus<一> Springboot框架使用MybatisPlus代码自动生成器 Mybatis-plus官网: https://mp.baomidou.com/ Demo ...

  3. MyBatis-plus 代码自动生成器

    MyBatis-plus  代码自动生成器 1.添加pom文件依赖 <!-- Mybatis-Plus 自动生成实体类--> <dependency> <groupId& ...

  4. Mybatis-Plus03 代码自动生成器

    先看完Mybatis-Plus01和Mybatis-Plus02再看Mybatis-Plus03 AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerato ...

  5. 专门为小白准备的入门级mybatis-plus-generator代码自动生成器,提高开发效率。值得收藏

    引入依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-g ...

  6. 单元测试系列之四:Sonar平台中项目主要指标以及代码坏味道详解

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6766994.html 众所周知Sona ...

  7. php调用C代码的方法详解和zend_parse_parameters函数详解

    php调用C代码的方法详解 在php程序中需要用到C代码,应该是下面两种情况: 1 已有C代码,在php程序中想直接用 2 由于php的性能问题,需要用C来实现部分功能   针对第一种情况,最合适的方 ...

  8. Understand:高效代码静态分析神器详解(转)

    之前用Windows系统,一直用source insight查看代码非常方便,但是年前换到mac下面,虽说很多东西都方便了,但是却没有了静态代码分析工具,很幸运,前段时间找到一款比source ins ...

  9. Understand:高效代码静态分析神器详解(一)

    Understand:高效代码静态分析神器详解(一) Understand   之前用Windows系统,一直用source insight查看代码非常方便,但是年前换到mac下面,虽说很多东西都方便 ...

随机推荐

  1. 数据可视化实例(十): 相关图(matplotlib,pandas)

    相关图 https://datawhalechina.github.io/pms50/#/chapter8/chapter8 导入所需要的库 import numpy as np # 导入numpy库 ...

  2. java学习第七天2020/7/12

    一. java继承使用的关键字是  extend class 子类 extends 父类{} 举一个类的例子: public class person { public String name; pu ...

  3. C#文件说明

    Bin -- 用来存放编译的结果,是默认的输出路径,项目属性—>配置属性—>输出路径. obj -- 用于存放编译过程中生成的中间临时文件.增量编译:项目属性—>配置属性—>高 ...

  4. HTTP版本比较

    HTTP2.0优势 1.采用二进制格式传输数据,而非http1.1文本格式,二进制格式在协议的解析和优化扩展上带来了跟多的优势和可能 2.对消息头采用Hpack进行压缩传输,能够节省消息头占用的网络流 ...

  5. Java常用开源库

    Java的经久不衰,很大程度上得益于Java的生态好.在日常开发中,我们也会经常使用到各种开源库和工具类,为了避免重复造轮子,本文将贴出工作及学习中会用到的部分开源库和工具类.Java的生态实在太大, ...

  6. jsp课堂笔记4 javabean

    Javabean是一个可重复使用的软件组件,实际上是一种java类 实现代码重复利用 易编写易维护易使用 jsp页面的主要任务是显示页面,不负责数据的逻辑业务处理 将数据处理过程中指派一个或多个bea ...

  7. TSGCTF-web Beginner's Web (js内置方法__defineSetter__)

    const fastify = require('fastify'); const nunjucks = require('nunjucks'); const crypto = require('cr ...

  8. e的存在性证明和计算公式的证明

    \(\quad\quad前言\quad\quad\\\) \(此证明,改编自中科大数分教材,史济怀版\\\) \(中科大教材,用的是先固定m,再放大m,跟菲赫金哥尔茨的方法一样.\\\) \(而我这里 ...

  9. sqlite文件的建立和as的应用,

    建立目录D:\android_projects\qrscan\app\src\main\assets把数据库文件d:\sqlite_files\device.db 拷贝到 D:\android_pro ...

  10. lua中 table.getn(t) 、#t、 table.maxn(t) 这三个什么区别?

    lua中 table.getn(t) .#t. table.maxn(t) 这三个什么区别? RTlocal t = {1,888,x= 999,b=2,5,nil,6,7,[10]=1,8,{z = ...