最近在寫進銷存系統,特地去學了easyui,誒誒誒,不得不說,easyui是我見過最丑的ui了,,好在它數據交互比較方便,但是我還是選擇easyui跟bootstrap混用啦啦啦啦啦啦,好像跑題了。。。言歸正傳。
easyui分頁應該算是比較簡單了,自動傳了兩個參數page跟rows
page指的是當前頁,rows指的是每頁的條數!(敲黑板!!)
其實思路也很簡單,首先要在controller獲取page跟rows,然后進行操作, 寫好sql語句,然后返回total與rows,注意是向前台返回rows跟total!!
關鍵代碼如下

1 @RequestMapping(value="/furnitureList",method=RequestMethod.POST,produces ={"application/json;charset=UTF-8"}) 2 @ResponseBody 3 public Map<String, Object> getAllFurniture(HttpServletRequest request) throws IOException{ 4 int currentPage=Integer.parseInt(request.getParameter("page")); 5 int pageSize=Integer.parseInt(request.getParameter("rows")); 6 7 //page=rows*(page-1)+1; 8 int total=furnitureService.getFurnitureTotal(); 9 List<Furniture> fList=furnitureService.getAllFurniture(currentPage,pageSize); 10 Map<String, Object> map=new HashMap<String,Object>(); 11 map.put("total", total); 12 map.put("rows", fList); 13 return map; 14 15 }

/** * 分頁獲取所有家具 * @param rows * @param page * @return */ List<Furniture> getAllFurniture(@Param("currentPage")int currentPage,@Param("pageSize") int pageSize);
這里的參數一定要加個@param注解啊,mybatis默認只能傳一個參數的,加上這個注解才能傳兩個,要不然會報錯

<select id="getAllFurniture" resultType="Furniture">
select furniture_id,furniture_name,ftype_id,input_price,output_price,company_id,furniture_number,description
from furniture
limit #{currentPage},#{pageSize}
</select>
好了,,這樣子分頁就大功告成了。
加油,,,路漫漫其修遠兮。。。。