性能分析插件

我们在平时的开发中,会遇到一些慢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. 数据可视化之DAX篇(六) 利用ISINSCOPE函数,轻松按层级计算占比

    https://zhuanlan.zhihu.com/p/70590683 关于占比,之前有篇文章(利用ALL和ALLSELECTED灵活计算占比)详细介绍了各种情况下占比的度量值. 经星友咨询,还有 ...

  2. 3dTiles 数据规范详解[4.2] i3dm瓦片二进制数据文件结构

    i3dm,即 Instanced 3D Model,实例三维模型的意思. 诸如树木.路灯.路边的垃圾桶.长椅等具有明显 重复 特征的数据.这类数据用得较少(笑,现在都喜欢搞BIM.倾斜摄影.精模.白模 ...

  3. Windows 磁盘分区后如何再合并&如何用Windows自带工具扩大某个分区

    Windows 磁盘分区后如何再合并&用Windows自带工具扩大某个分区 注:此方法有一定的成功率,更加完善可行的方法请看http://www.diskgenius.cn/help/part ...

  4. Go的100天之旅-08字符串

    目录 简介 UTF-8字符 字符串的常用操作 简介 字符串在各种编程语言中都是很基础的一种类型,在Go中字符串简单理解就是一个数组,数组里面的元素是byte类型.因此基本上拥有类似数组的全部特性.例如 ...

  5. 利用tox打造自动自动化测试框架

    什么是tox tox官方文档的第一句话 standardize testing in Python,意思就是说标准化python中的测试,那是不是很适合测试人员来使用呢,我们来看看他究竟是什么? 根据 ...

  6. three.js 数学方法之Vector3

    今天郭先生来说一说three.js的Vector3,该类表示的是一个三维向量(3D vector). 一个三维向量表示的是一个有顺序的.三个为一组的数字组合(标记为x.y和z),可被用来表示很多事物, ...

  7. java 之死循环

    public class StringTest { public static void main(String[] args) { System.out.println(getStringCount ...

  8. 6-Pandas之缺失值处理

    一.了解缺失值 通常使用 NA('not available')来代指缺失值 在Pandas的数据结构中,缺失值使用 NaN('Not a Number')进行标识 除了汇总统计方法,还可以使用isn ...

  9. Python os.isatty() 方法

    概述 os.isatty() 方法用于判断如果文件描述符fd是打开的,同时与tty(-like)设备相连,则返回true, 否则False.高佣联盟 www.cgewang.com 语法 isatty ...

  10. Python time sleep()方法

    描述 Python time sleep() 函数推迟调用线程的运行,可通过参数secs指秒数,表示进程挂起的时间.高佣联盟 www.cgewang.com 语法 sleep()方法语法: time. ...