搜索
首页
笔记
案例
关于
课程列表
MyBatis-Plus
CURD
自动填充
条件构造器
ActiveRecord
代码生成器
插件
逻辑删除
课程导航
计算机基础知识
C
Linux
linux常用软件
计算机网络
程序员修养
设计模式
工具
Git
composer
vim
IntelliJ IDEA
wireshark
laravel
Spring
SpringMVC
Maven
数据库
MySQL
Redis
MongoDB
JDBC
Mybatis
MyBatis-Plus
服务端编程
PHP
Java
shell script
JavaWeb
HTML / CSS
HTML
CSS
HTML5
CSS3
BOOTSTRAP
JavaScript
JavaScript
JQuery
layui
代码生成器
逻辑删除
插件
用了mybatisplus就避免不了使用分页插件。 - 在spring中引入分页插件 - 在springboot中引入分页插件 ## spring中引入分页插件 ### 注册 ```
``` ### 使用 ``` ApplicationContext cx = new ClassPathXmlApplicationContext("spring.xml"); EmployeeMapper mapper = cx.getBean("employeeMapper", EmployeeMapper.class); Page
employeePage = new Page<>(2, 5); // 第二页,每页5条 List
employees = mapper.selectPage(employeePage, new EntityWrapper<>()); employees.forEach(System.out::println); ``` ### Page对象 Page对象中有一些非常好用的方法: ```java ApplicationContext cx = new ClassPathXmlApplicationContext("spring.xml"); EmployeeMapper mapper = cx.getBean("employeeMapper", EmployeeMapper.class); Page
employeePage = new Page<>(2, 5); List
employees = mapper.selectPage(employeePage, new EntityWrapper<>()); employeePage.setRecords(employees); // 将查询结果集存放在page对象实例中 System.out.println("当前页:"+employeePage.getCurrent()); System.out.println("是否有上一页:"+employeePage.hasPrevious()); System.out.println("是否有下一页:"+employeePage.hasNext()); System.out.println("总记录数:"+employeePage.getTotal()); ``` ### 执行分析插件 com.baomidou.mybatisplus.plugins.SqlExplainInterceptor SQL 执行分析拦截器,只支持 MySQL5.6.3 以上版本.该插件的作用是分析 DELETE UPDATE 语句,防止小白或者恶意进行 DELETE UPDATE 全表操作 只建议在开发环境中使用,不建议在生产环境使用。 原理:在插件的底层 通过 SQL 语句分析命令:Explain 分析当前的 SQL 语句,根据结果集中的 Extra 列来断定当前是否全表操作。 #### 配置 ```xml
``` #### 使用 ```java ApplicationContext cx = new ClassPathXmlApplicationContext("spring.xml"); EmployeeMapper mapper = cx.getBean("employeeMapper", EmployeeMapper.class); mapper.delete(null); ``` ## springboot中引入分页插件 MyBatis Plus自带分页插件,只要简单的配置即可实现分页功能 ### 配置 ```java @Configuration public class MyMybatisPlusConfig { @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } } ``` ### 使用 ```java @Test void test5 () { Page
page = new Page<>(2, 5);// 第二页,每页5条数据 Page
employeePage = employeeMapper.selectPage(page, null); //返回对象得到分页所有数据 long pages = employeePage.getPages(); //总页数 long current = employeePage.getCurrent(); //当前页 List
records = employeePage.getRecords(); //查询数据集合 long total = employeePage.getTotal(); //总记录数 boolean hasNext = employeePage.hasNext(); //下一页 boolean hasPrevious = employeePage.hasPrevious(); //上一页 System.out.println(pages); System.out.println(current); System.out.println(records); System.out.println(total); System.out.println(hasNext); } ```
代码生成器
逻辑删除
文章目录