提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
导入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
后去做相关配置
pagehelper.helper-dialect=mysql pagehelper.reasonable=true pagehelper.support-methods-arguments=true pagehelper.params=count=countSql pagehelper.page-size-zero=true spring.main.allow-circular-references=true
Action.java
package com.han.pojo;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
*@author han
*@version 1.0
@since 2022-12-22 21:59
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Action {
private Integer actionId;
private String orderSn;
private Integer actionUser;
private Integer orderStatus;
private Integer payStatus;
private Integer shippingStatus;
private String actionNote;
private String actionTime;
private String statusDesc;
}
ActionMapper
/**
* 查询
* @return
*/
List<Action> get(String orderSn);
ActionService与ActionMapper方法一致
ActionServiceImpl
@Override
public List<Action> get(String orderSn) {
return actionMapper.get(orderSn);
}
ActionMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.han.mapper.ActionMapper">
<select id="get" resultType="Action" parameterType="com.han.pojo.Action">
select * from action
<if test="orderSn!= null and orderSn!='' and orderSn.length!=0">
where order_sn like concat('%',#{orderSn},'%')
</if>
</select>
ActionContoller
PageNum当前页
PageSize每页条数
orderSn订单编号
@RequestMapping("get")
public String get(Model model,String orderSn,
@RequestParam(value ="PageNum",defaultValue = "1") Integer PageNum,
@RequestParam(value ="PageSize",defaultValue = "2",required = false) Integer PageSize){
PageHelper.startPage(PageNum,PageSize);
List<Action> list = service.get(orderSn);
PageInfo<Action> pageInfo = new PageInfo<>(list);
if (orderSn!=null){
model.addAttribute("orderSn",orderSn);
}
model.addAttribute("pageInfo",pageInfo);
System.out.println(orderSn);
return "index";
}
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div align="center">
<form method="post" th:action="${get}">
订单编号 <input type="text" name="orderSn"> <input type="submit" value="查询">
</form>
</div>
<table border="1" align="center">
<tr>
<th>操作id</th>
<th>订单编号</th>
<th>操作人</th>
<th>订单状态</th>
<th>支付状态</th>
<th>配送状态</th>
<th>操作记录</th>
<th>操作时间</th>
<th>操作描述</th>
</tr>
<tr th:each="List:${pageInfo.list}">
<td th:text="${List.actionId}"></td>
<td th:text="${List.orderSn}"></td>
<td th:text="${List.actionUser}"></td>
<td th:text="${List.orderStatus}"></td>
<td th:text="${List.payStatus}"></td>
<td th:text="${List.shippingStatus}"></td>
<td th:text="${List.actionNote}"></td>
<td th:text="${List.actionTime}"></td>
<td th:text="${List.statusDesc}"></td>
</tr>
<div th:if="${pageInfo.getPages>0}" align="center">
<!--当前页-->
<span th:text="'当前页:'+${pageInfo.getPageNum}"></span>
<!-- 首页作为第一页不可点击-->
<a th:href="@{get(PageNum=1)}+'&orderSn='+${orderSn}">首页</a>
<span th:if="${pageInfo.PageNum==1}">
<a onclick="return false">上一页</a>
</span>
<span th:unless="${pageInfo.PageNum==1}">
<a th:href="@{get(PageNum=${pageInfo.PageNum-1})}+'&orderSn='+${orderSn}">上一页</a>
</span>
<span th:each="i:${#numbers.sequence(1,pageInfo.getPages)}">
<a th:href="@{get(PageNum=${i})}" th:text="${i}">1</a>
</span>
<span th:if="${pageInfo.getPages==pageInfo.getPageNum}">
<a onclick="return false">下一页</a>
</span>
<span th:unless="${pageInfo.getPages==pageInfo.getPageNum}">
<a th:href="@{get(PageNum=${pageInfo.PageNum+1})}+'&orderSn='+${orderSn}">下一页</a>
</span>
<a th:href="@{get(PageNum=${pageInfo.getPages})}+'&orderSn='+${orderSn}">末页</a>
<span th:text="'总条数'+${pageInfo.getTotal}"></span>
</div>
</table>
</body>
</html>