分页
来源:互联网 发布:中国产业生产率数据库 编辑:程序博客网 时间:2024/06/05 06:35
在pom文件中加两个依赖jar包
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.0.0</version></dependency><!-- https://mvnrepository.com/artifact/com.github.jsqlparser/jsqlparser --><dependency> <groupId>com.github.jsqlparser</groupId> <artifactId>jsqlparser</artifactId> <version>0.9.5</version></dependency>
mybatis-config.xml 里配置插件:
<!-- 配置分页插件 --><plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 4.0.0以后版本可以不设置该参数 --> <property name="dialect" value="mysql"/> </plugin></plugins>
jsp页面:
注意:(<c:forEach items="${pagelist.list}" var="s"> 用页面list调用原本的list集合)
共<span>${pagelist.total}条记录当前显示</span><span>现在显示第${pagelist.pageNum}页</span><a href="/stock/mhselect.action?pageNo=${pagelist.firstPage}&pageSize=${pagelist.pageSize}" >首页</a><c:choose> <c:when test="${pagelist.isFirstPage==true}"> <a href="/stock/mhselect.action?pageNo=${pagelist.firstPage}&pageSize=${pagelist.pageSize}" >上一页</a> </c:when> <c:otherwise> <a href="/stock/mhselect.action?pageNo=${pagelist.prePage}&pageSize=${pagelist.pageSize}" >上一页</a> </c:otherwise></c:choose><c:choose> <c:when test="${pagelist.isLastPage==true}"> <a href="/stock/mhselect.action?pageNo=${pagelist.lastPage}&pageSize=${pagelist.pageSize}" >下一页</a> </c:when> <c:otherwise> <a href="/stock/mhselect.action?pageNo=${pagelist.nextPage}&pageSize=${pagelist.pageSize}" >下一页</a> </c:otherwise></c:choose><a href="/stock/mhselect.action?pageNo=${pagelist.lastPage}&pageSize=${pagelist.pageSize}">尾页</a>
controller不分页的代码
@RequestMapping(value = "/mhselect.action", method = RequestMethod.GET)public String toall(String stockName, Model model) { HashMap<String, Object> map = new HashMap<>(); System.out.println(stockName); List<Stock> list = stockService.mhselect(stockName); System.out.println(list); model.addAttribute("list", list); return "/all";}controller分页后的代码://查询所有带分页@RequestMapping(value = "/mhselect.action",method = RequestMethod.GET)public String findStockAll(Model model,String pageNo, String pageSize,String stockName){ /** * * @param pageNum 页码 * @param pageSize 每页显示数量 * @param count 是否进行count查询 * @param reasonable 分页合理化,null时用默认配置 * @param pageSizeZero true且pageSize=0时返回全部结果,false时分页,null时用默认配置 */ int num = 1; int size = 3; if(pageNo != null && !"".equals(pageNo)) { num = Integer.parseInt(pageNo); } if (pageSize != null && !"".equals(pageSize)) { size = Integer.parseInt(pageSize); } //开始分页 PageHelper.startPage(num,size); //查询数据库信息 List<Stock> list = stockService.mhselect(stockName); System.out.println(list); //将信息放入Pagelist进行分页 PageInfo<Stock> pagelist = new PageInfo<Stock>(list); System.out.println(pagelist.getPageNum()); System.out.println(pagelist.getPageSize()); System.out.println(pagelist.getTotal()); System.out.println(pagelist.getFirstPage()); System.out.println(pagelist.getLastPage()); System.out.println(pagelist.getPrePage()); System.out.println(pagelist.getNextPage()); model.addAttribute("pagelist",pagelist); return "/all";}
阅读全文
0 0
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 路由界面
- AngularJS实现对用户信息的增删改查
- 童年回忆
- SpringMVC和struts,当然选前者了,后者恶心了
- dlib 15 dlib自带demo 基于DNN的车辆检测
- 分页
- SAP HANA Express Edition (HXE)-二进制安装使用步骤
- 以python中类方法为例来说说自定义模块导入的三种方法
- 转载了一个调用摄像头拍照的cordova案例
- AngularJs_Service
- 数据预处理(2)—— One-hot coding 独热编码#分别使用 pandans.dummies 和 sklearn.feature_extraction.DictVectorizer 进行处理
- 社群会员必看:你关心的问题,答案都在这里了
- Spring Boot启动流程
- Linux之whereis命令