springboot中分页插件的使用

news/2024/9/18 0:54:26/ 标签: spring boot, java

安装依赖

这里有个版本的报错,循环依赖的问题,大家可以去具体查下,我这是sp3,所以要选择高点的版本,否则启动会报错

<!--mybatis起步依赖--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><!--mysql驱动--><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><!--分页插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.4.1</version></dependency>

看到这个,就说明安装成功了
在这里插入图片描述

application.propertis配置文件

server.port=9090
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springapp01
spring.datasource.username=root
spring.datasource.password=123456
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
mybatis.configuration.map-underscore-to-camel-case=true
  • controller
java">import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;import java.time.LocalDate;
import java.util.List;/*** 员工管理Controller*/
@RestController
@Slf4j
@RequestMapping("/emps")
public class EmpController {@Autowiredprivate EmpService empService;@GetMappingpublic Result page(String name,Short gender,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){log.info("{},{}.{},{},page:{},pageSize:{}",name,gender,begin,end,page, pageSize);//PageBean pageBean = empService.page(page, pageSize);PageBean pageBean = empService.pageHelper(name,gender,begin,end,page, pageSize);return Result.success(pageBean);}/*** 批量删除员工信息* delete from emp where id in (1,2,3)*/@DeleteMapping("/{ids}")public  Result delete(@PathVariable List<Integer> ids) {log.info("批量删除操作 {}", ids);empService.delete(ids);return Result.success();}
}
  • services

基础类

java">/*** 员工管理*/
public interface EmpService {PageBean page(Integer page, Integer pageSize);PageBean pageHelper(String name, Short gender, LocalDate begin,LocalDate end, Integer page, Integer pageSize);void delete(List<Integer> ids);
}

实现类

java">package com.itheima.service.impl;import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.time.LocalDate;
import java.util.List;@Service
public class EmpServiceImpl implements EmpService {@Autowiredprivate EmpMapper empMapper;//自己实现的page方法@Overridepublic PageBean page(Integer page, Integer pageSize) {Long count = empMapper.count();Integer start = (page - 1) * pageSize;List<Emp> page1 = empMapper.page(start, pageSize);return new PageBean(count, page1);}@Overridepublic  PageBean pageHelper(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize){//设置分页参数PageHelper.startPage(page, pageSize);List<Emp> empList = empMapper.listAll(name, gender, begin,end);Page<Emp> p = (Page<Emp>) empList;return new PageBean(p.getTotal(), p.getResult());}@Overridepublic void delete(List<Integer> ids){empMapper.delete(ids);}
}
  • mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><select id="listAll" resultType="com.itheima.pojo.Emp">select * from emp<where><if test="name != null">name like concat('%',#{name},'%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if></where>order by update_time desc</select><delete id="delete">delete from emp where id in<foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach></delete>
</mapper>

http://www.ppmy.cn/news/1519414.html

相关文章

c/c++基础及类和对象汇总

目录 c基础 extern关键字及c中&#xff08;隐式类型转换时&#xff09;的引用 c中的引用&#xff08;&&#xff09;及&做返回值问题 c语言中的宏函数及c的内联函数及auto及NULL 计算类的大小及深入理解this指针&#xff08;深入浅出&#xff09; c中的const权限及s…

C# 反射和特性练习代码

反射 using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Metadata.Ecma335; using System.Runtime;class Test {private int b;pub…

ARM/Linux嵌入式面经(三二):百度

文章目录 RTOS了解吗,展开讲一下对RTOS的线程和任务管理相关的有了解吗RTOS的线程和任务管理相关了解追问有深度的技术问题及答案vivado这个硬件平台怎么用的Vivado硬件平台使用了解追问有深度的技术问题及答案项目系统架构、配置是怎样的项目系统架构与配置系统架构配置追问有…

WPF中使用Echarts显示图表

在WPF中使用ECharts来显示图表&#xff0c;你需要将ECharts嵌入到WPF应用程序中。我们这里介绍两种方法显示图表&#xff1a; 目录 一、ECharts是一个基于JavaScript的开源可视化图表库&#xff0c;因此我们需要使用WebView控件来承载一个嵌入式浏览器&#xff0c;这样就可以…

JVM 性能分析 —— CMS 老年代并发 GC 触发条件与压缩式 GC (升级为 Full GC)触发条件

文章目录 CMS 触发老年代 GC 条件foreground collector&#xff08;前台收集&#xff09;background collector&#xff08;后台收集&#xff09; MSC&#xff08;mark-sweep-compact 压缩式 GC&#xff09; CMS 触发老年代 GC 条件 先看看触发老年代GC的条件。CMS GC 在实现上…

线程池在接受到30个比较耗时的任务时的状态,在前面30个比较耗时的任务还没执行完成的情况下,再来多少个任务会触发拒绝策略?

目录 一、提出问题 二、解答 问题 1: 线程池在接受到30个比较耗时的任务时的状态 问题 2: 在前面30个比较耗时的任务还没执行完成的情况下&#xff0c;再来多少个任务会触发拒绝策略&#xff1f; 总结 一、提出问题 我们首先自定义一个线程池&#xff1a; new ThreadPoo…

python基本语法总结

参考&#xff1a; Python 基础语法 | 菜鸟教程 (runoob.com) Python 语言与 Perl&#xff0c;C 和 Java 等语言有许多相似之处。但是&#xff0c;也存在一些差异。 在本章中我们将来学习 Python 的基础语法&#xff0c;让你快速学会 Python 编程。 第一个Python程序 python编写…

【python】OpenCV—Multi Human Pose Estimation

文章目录 1、背景介绍2、关键点检测模型3、源码与结果4、源码解读——检测关键点5、源码解读——找到有效对6、源码解读——组装个人关键点7、涉及到的库cv2.dnn.blobFromImage 8、参考 1、背景介绍 【python】OpenCV—Single Human Pose Estimation 本文以 COCO 格式为例&am…

内存管理笔记

1、内存管理简介 在计算机系统中&#xff0c;变量、中间数据一般存放在系统存储空间中&#xff0c;只有在实际使用时才将它们从存储空间调入到中央处理器内部进行运算。通常存储空间可以分为两种&#xff1a;内部存储空间和外部存储空间。内部存储空间访问速度比较快&#xff…

中文科技核心

“中文科技核心”通常指的是在中文领域内具有重要影响力和学术价值的科技研究或出版物。这些核心期刊和论文集主要集中在自然科学、工程技术、计算机科学等领域&#xff0c;代表了该领域的前沿研究成果。以下是关于中文科技核心的一些要素和相关内容。 1. 中文科技核心期刊的定…

Transformer参数量和复杂度

在算法岗面试中经常会问到Transformer相关的基础知识。 首先需要清楚Transformer的参数量和复杂度分别在算什么。 定义&#xff1a; 参数量&#xff1a;神经网络中有很多参数矩阵&#xff0c;这个矩阵大小的和就是参数量&#xff0c;静态的&#xff0c;摆在那就在那&#xff…

通过 Filter 改写请求的 Response

通过 Filter 改写请求的 Response 1、自定义 ResponseWrapper 自定义 ResponseWrapper&#xff0c;用于获取 Response Data public class RewriteRespWrapper extends HttpServletResponseWrapper {private final ByteArrayOutputStream output;private ServletOutputStream…

华为 HCIP-Datacom H12-821 题库 (3)

有需要题库的可以看主页置顶 1.运行 OSPF 协议的路由器在交互 DD 报文时&#xff0c;会使用以下哪一个参数选举主从关系&#xff1f; A、接口的 IP 地址 B、接口的 DR 优先级 C、Area ID D、Router ID 答案&#xff1a;D 解析&#xff1a; Router-ID 大的为主&#xff0c;小的…

初爽Stream流

体验Stream流的作用&#xff1a; 需求&#xff1a; 按照下面的要求完成集合的创建和遍历 创建一个集合&#xff0c;存储多个字符串元素 要求&#xff1a; 1.把所有以“张”开头的元素存储到新集合中 2.把“张”开头的&#xff0c;长度为3的元素再存储到新集合中 3.遍历打…

Java小项目IDEA怎么打成jar包

使用IDEA打jar包 在file选项中找 打开jar包所在位置&#xff1a; 将jar包拿出来 直接点击jar包就可以运行

Linux tty模式下无法使用回滚功能解决(shift+pgup方法不管用)

Linux tty模式下无法使用回滚功能解决&#xff08;shiftpgup方法不管用&#xff09; 自从内核5.9版本以后&#xff0c;回滚功能就被取消&#xff1a;fbcon: remove soft scrollback code 此前是可以使用 Shift PageUp/PageDown 来滚动的。现在假如我们想查看屏幕以外的文字&…

算法训练营|图论第二天 99.岛屿数量 100.岛屿的最大面积

题目&#xff1a;99.岛屿数量 题目链接&#xff1a; 99. 岛屿数量 (kamacoder.com) 代码&#xff1a; 深度优先搜索&#xff1a; #include<bits/stdc.h> using namespace std; int dir[4][2] { 0,1,1,0,-1,0,0,-1 }; void dfs(vector<vector<int>>&…

MySQL唯一索引大小写敏感性问题及字符集深入解析

1. 问题背景与描述 在实际生产环境中&#xff0c;我们遇到了一个插入重复异常的问题。具体表现在长链接转换为短链接的过程中&#xff0c;生成的短链被插入数据库时触发了唯一索引的冲突错误。错误的根本原因在于数据库使用了不区分大小写的排序规则&#xff0c;导致两个看似不…

Linux下安装MySQL8.0

一、安装 1.下载安装包 先创建一个mysql目录&#xff0c;在将压缩包下载到此 # 下载tar包 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz等待下载成功 2.解压mysql8.0安装包 tar xvJf mysql-8.0.20-linux-glibc2.12-x86…

尝试用java spring boot+VUE3实现前后端分离部署

前言 这几天开学了&#xff0c;公司这边几个和学校对接的项目都挺忙的&#xff0c;然后我又开始有点闲的情况了。问大佬能不能继续看看若依的项目&#xff0c;大佬让我自己去学了。在看若依的项目的时候在想&#xff0c;python的FLASK后端实现和JAVA spring boot的实现差别大不…