用pageHelper分頁時,隻要是能夠擷取前台傳來的兩個參數page和rows基本就完成了很大一部分。
擷取方法:定義兩個變量page和rows,設定對應的getter,setter方法,在方法中直接擷取就能打得。easyUI預設的每次請求時都會傳遞這兩個參數。
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcucTM2EWN4MzNwIDMxIGZ2IDZwIDNzE2NkZjZiNWYzEmYfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
public int getRows() {
return rows;
public void setRows(int rows) {
this.rows = rows;
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcucTM2EWN4MzNwIDMxIGZ2IDZwIDNzE2NkZjZiNWYzEmYfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
public String getAllPages() {
List<Emp> plist = empDao.findAll();
PageHelper.startPage(page, rows);
List<Emp> elist = empDao.findAll();
// 判斷
if (elist.size() > 0) {
map.put("total", plist.size());
map.put("rows", elist);
return SUCCESS;
}
return ERROR;
傳回的資料必須轉成json格式
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcucTM2EWN4MzNwIDMxIGZ2IDZwIDNzE2NkZjZiNWYzEmYfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
<!-- 配置查詢所有方法Action -->
<action name="listAction" class="EmpAction" method="getAllPages">
<result name="success" type="json">
<param name="root">map</param>
</result>
</action>