<div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages']}+ ' 頁'"></b></a> <a class="num" th:if="${result.resultMap['hasPreviousPage']} == true" th:href="@{'/report/receivePage?currentPage=' + ${result.resultMap['prePage']} + '&sCus=' + ${result.sCus}+ '&sIsPaid=' + ${result.sIsPaid}+ '&start=' + ${result.start}+ '&end=' + ${result.end}}" >上一頁</a> <a class="num" th:href="@{'/report/receivePage?currentPage=' + ${result.resultMap['nextPage']}+'&sCus=' + ${result.sCus}+ '&sIsPaid=' + ${result.sIsPaid}+ '&start=' + ${result.start}+ '&end=' + ${result.end}}" th:if="${result.resultMap['hasNextPage']} == true">下一頁</a> </div>
controller層
if(!"null".equals(dto.getsCus())){ conditionMap.put("sCus",dto.getsCus()); } if(dto.getStart() != null && dto.getStart() != ""){ // 將時間字符串轉換為時間對象 DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); try { conditionMap.put("start",format1.parse(dto.getStart())); } catch (ParseException e) { e.printStackTrace(); } }
dto
public class ConditionDto { private Integer currentPage=1; private Integer pageSize; private String start; private String end; private String sCus; }
最近在使用springboot+thymeleaf+pageHelper做帶條件分頁的時候遇到了一些問題,我們在做帶條件查詢分頁的時候,搜索條件需要拼接到url路徑后面,不然翻頁的時候,查詢出來的數據是不帶條件的。但是直接拼接到url后面,所有的數據都會被轉換成String類型,這時,我們需要在controller層做一下判斷與數據類型的轉換。問題暫時解決了,不過代碼還有待優化!