创建项目 第一步(完成以下操作进行下一步): 第二步: 一、 原理概述 PageHelper是mybatis的一个插件,内部实现了一个PageInterceptor拦截器。Mybatis会加载这个拦截器到拦截器链中。
PageHelper是mybatis的一个插件,内部实现了一个PageInterceptor拦截器。Mybatis会加载这个拦截器到拦截器链中。在我们使用过程中先使用PageHelper.startPage这样的语句在当前线程上下文中设置一个ThreadLocal变量,再利用PageInterceptor这个分页拦截器拦截,从ThreadLocal中拿到分页的信息,如果有分页信息拼装分页sql(limit语句等)进行分页查询,最后再把ThreadLocal中的东西清除掉。
com.GitHub.pagehelper pagehelper-spring-boot-starter 1.4.1
#pageHelper 分页插件的配置 pagehelper: auto-dialect: true reasonable: true support-methods-arguments: true params: count=countSql
package com.boot.springboot1223.pojo;import com.baomidou.mybatisplus.annotation.IdType;import com.baomidou.mybatisplus.annotation.TableField;import com.baomidou.mybatisplus.annotation.TableId;import com.baomidou.mybatisplus.annotation.TableName;import lombok.Data;import java.io.Serializable;import java.util.Date;@Data@TableName("action")public class Action{ @TableId(type = IdType.AUTO) 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; @TableField(exist = false) private String orderTime;}
package com.boot.springboot1223.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.boot.springboot1223.pojo.Action;import org.apache.ibatis.annotations.Mapper;import java.util.List;@Mapperpublic interface ActionMapper extends BaseMapper { List findPage(Action action);}
package com.boot.springboot1223.service;import com.baomidou.mybatisplus.extension.service.IService;import com.boot.springboot1223.pojo.Action;import com.github.pagehelper.PageInfo;import java.util.List;public interface ActionService extends IService { PageInfo findPage(Action action,Integer pageIndex,Integer pageSize);}
package com.boot.springboot1223.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import com.boot.springboot1223.mapper.ActionMapper;import com.boot.springboot1223.pojo.Action;import com.boot.springboot1223.service.ActionService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class ActionServiceImpl extends ServiceImpl implements ActionService { @Autowired private ActionMapper actionMapper; @Override public PageInfo findPage(Action action, Integer pageIndex, Integer pageSize) { //调用分页插件的工具类 计算总页数 PageHelper.startPage(pageIndex,pageSize); //获取所有数据 List page = actionMapper.findPage(action); //获取所有的数据直接给pageInfo PageInfo pageInfo=new PageInfo(page); return pageInfo; }}
package com.boot.springboot1223.controller;import com.boot.springboot1223.pojo.Action;import com.boot.springboot1223.pojo.Order;import com.boot.springboot1223.service.ActionService;import com.boot.springboot1223.service.OrderService;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.WEB.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;@Controllerpublic class ActionController { @Autowired private ActionService actionService; @RequestMapping("/findPage") public String findPage( Action action, @RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize",defaultValue = "1",required = false) Integer pageSize, Model model ){ PageInfo page = actionService.findPage(action,pageIndex, pageSize); model.addAttribute("path","findPage?pageIndex="); model.addAttribute("page",page); model.addAttribute("action",action); return "list"; }}
页面显示
来源地址:https://blog.csdn.net/qq_57512436/article/details/128446865
--结束END--
本文标题: pagehelper插件进行分页
本文链接: https://www.lsjlt.com/news/393931.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-22
2024-05-22
2024-05-22
2024-05-22
2024-05-22
2024-05-22
2024-05-22
2024-05-21
2024-05-21
2024-05-21
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模 安全指南 Osprey 游戏分析 游戏调试 游戏图形 游戏物理 开源库 魔方破解 游戏安全 反作弊 安全最佳实践 游戏逻辑 LaVie 域名转让平台
0