springboot+themlelf+pagehelper分页

spring boot+themlef+pagehelper分页插件

1.导入依赖

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>

2.配置文件进行配置

pagehelper.offsetAsPageNum=true
pagehelper.rowBoundsWithCount=true
pagehelper.pageSizeZero=true
pagehelper.reasonable=false
pagehelper.params=pageNum=pageHelperStart;pageSize=pageHelperRows;
pagehelper.supportMethodsArguments=false

3.后台接口

   @GetMapping("/getFileList")
 public ModelAndView getFileList(String parentfile,String rootfile, ModelAndView modelAndView,@RequestParam(required = false,defaultValue = "1",value = "pageNum") int pageNum){
        PageHelper.startPage(pageNum, 10);
        List<File> list=fileService.quaryAllByParent(parentfile,rootfile);
        modelAndView.addObject("list",list);
        PageInfo pageInfo=new PageInfo<>(list,4);//导航页
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("fileList");
        return  modelAndView;
    }

4.前台代码

<div class="page">
  <span class="pageinfo">共<label id="total" th:text="${pageInfo.total}"></label>条/
           <label th:text="${pageInfo.pages}" style="color: crimson"></label> 页 
  </span> 
  <a th:href="@{/file/getFileList(parentfile=${list.get(0).getParentfile()},rootfile=${list.get(0).getRootfile()},pageNum=1)}" class="pagefirst">首页
  </a>
  <a th:if="${pageInfo.pageNum>1}" th:href="@{/file/getFileList(parentfile=${list.get(0).getParentfile()},rootfile=${list.get(0).getRootfile()},pageNum=${pageInfo.getPageNum()-1})}" >上一页
  </a>
  <b th:each="nav:${pageInfo.navigatepageNums}">
    <a th:href="@{/file/getFileList(parentfile=${list.get(0).getParentfile()},rootfile=${list.get(0).getRootfile()},pageNum=${nav})}" th:if="${nav!=pageInfo.pageNum}">
    </a>
	<span style="font-weight: bold;background: #6faed9;" th:if="${nav==pageInfo.pageNum}" th:text="${nav}">
    </span>
  </b>
  <a  th:if="${pageInfo.pageNum<pageInfo.getPageSize()}" th:href="@{/file/getFileList(parentfile=${list.get(0).getParentfile()},rootfile=${list.get(0).getRootfile()},pageNum=${pageInfo.getPageNum()+1})}" >下一页
  </a>
  <a th:href="@{/file/getFileList(parentfile=${list.get(0).getParentfile()},rootfile=${list.get(0).getRootfile()},pageNum=${pageInfo.getPages()})}" class="pageend">尾页
  </a>

</div>
posted @ 2020-09-17 07:57  知南而北游  阅读(427)  评论(0编辑  收藏  举报