spring boot 中thymeleaf 分页(上一页,下一页,首页,尾页)

controller

@GetMapping(value = "/page")
public String findGoodsPage(Model model, @RequestParam(value="pageNum") String pageNum){
   Page pages=goodsService.findGoodsNoCriteria(Integer.parseInt(pageNum),20,"commentNum"); 

    if(pageNum==null){
        pageNum="1";
    }
    int pagenum=Integer.parseInt(pageNum); 
    model.addAttribute("page",pages);
    model.addAttribute("pageNum",pagenum);
    model.addAttribute("totalPages",pages.getTotalPages());
    model.addAttribute("totalElements",pages.getTotalElements());
    return "list";
}

thymeleaf中的html页面:

<table>
  <tr>
  <td><a th:href="@{/goods/page?pageNum=0}">首页a>td>
    <td th:switch="${pageNum}">
      <p th:case="1"> <a th:href="@{/goods/page?pageNum=1}">上一页a>p>
      <p th:case="*"><a th:href="@{/goods/page(pageNum=${pageNum-1})}">上一页a>p>
    td>
     <td th:switch="${pageNum}">
       <p th:case="${totalPages}"><a th:href="@{/goods/page(pageNum=${totalPages})}">下一页a>p>
       <p th:case="*"><a th:href="@{/goods/page(pageNum=${pageNum+1})}">下一页a>p>
     td>
     <td><a th:href="@{/goods/page(pageNum=${totalPages})}">尾页a>td>
  tr>
table>

你可能感兴趣的:(前端)