guns框架分页实现
生活随笔
收集整理的這篇文章主要介紹了
guns框架分页实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先注意分頁的maven依賴一般有倆種,不能混用,否者出錯,guns中默認使用如下Page依賴
<!-- mybatis的orm插件 --><dependency> <groupId>com.baomidou</groupId><artifactId>mybatisplus-spring- boot-starter</artifactId><version>1.0.4</version> </dependency> <dependency><groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.0.7</version></dependency>導入是:
import com.baomidou.mybatisplus.plugins.Page;示例:
/*** 前臺快訊列表*/ @RequestMapping(value = "/newsList") public Object newsList(HttpSession session, @RequestParam(required=true,defaultValue="1") Integer page, Model model) {User user= (User)session.getAttribute(Constants.USER_SESSION);if(user!=null&& !"".equals(user)){model.addAttribute("user",user);}Page<News> newsPage=new Page<>(page,15);EntityWrapper<News> ew = new EntityWrapper<News>();ew.orderDesc(Collections.singleton("createTime"));Page<News> newsList=newsService.selectPage(newsPage,ew);model.addAttribute("newsList",newsList);return new ModelAndView(PREFIX_2+"newsList.html","homeModel",model); }這是前臺列表頁面的控制分頁顯示的代碼,其中Page<> newsPage=new Page<>(page,15);是要使用的分頁語句,page代指起始頁,他由前臺用戶點擊的頁碼傳遞到后臺實現分頁內容切換,15是一頁顯示的數量
?
如何實現 動態分頁呢?比如有對分頁的結果有按照某個字段排序的需求.....?
通過 import com.baomidou.mybatisplus.mapper.EntityWrapper;實現,如上面代碼中
EntityWrapper<News> ew = new EntityWrapper<News>();
ew.orderDesc(Collections.singleton("createTime"));
創建EntityWrapper示例,?orderDesc代指按照什么來降序排列,ew的方法還有很多,我這里是按照createTime排序即可,當然更加復雜的查詢需求參考官網的使用介紹
最后將ew 作為selectPage的第二個參數即可實現動態排序啦!
注意newsService繼承了IService<News>,如下面導入 IService
import com.baomidou.mybatisplus.service.IService;其中Constants內容:
package com.stylefeng.guns.modular.system.tools;public class Constants {public final static String USER_SESSION="userSession";public final static String FILEUPLOAD_ERROR_1="* APK信息不完整";public final static String FILEUPLOAD_ERROR_2="* 上傳失敗";public final static String FILEUPLOAD_ERROR_3="* 上傳文件格式不正確";public final static String FILEUPLOAD_ERROR_4="* 上傳文件過大!";public final static String SYS_MESSAGE="massage";/*public final static String USER_SESSION="userSession";*/public final static int honorPageSize=6;public final static int deptSize=4;public final static int newsSize=6;public final static int reportSize=12;public final static int pageSize=5;public final static String SESSION_BASE_MODEL="baseModel";}?
總結
以上是生活随笔為你收集整理的guns框架分页实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常用的四种CSS样式表格
- 下一篇: c语言程序库文件,c语言标准函数库