MyBatis+springMVC+easyUI (dataGirl)實現分頁(轉載)

頁面展示效果。

頁面代碼:

[html] view plaincopy
  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>  
  2. <%@include file="/common/common.jsp" %>  
  3. <html>  
  4. <head>  
  5.     <title></title>  
  6. </head>  
  7. <body>  
  8. <h2>樣片庫管理</h2>  
  9.   
  10. <div style="padding:8px;height:auto">  
  11.     參數項名稱: <input class="easyui-validatebox" type="text" name="name" data-options="required:true">  
  12.     創建時間: <input class="easyui-datebox" name="createTime" style="width:80px">  
  13.     <a href="#" class="easyui-linkbutton" iconCls="icon-search">查找</a>  
  14.     <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>  
  15. </div>  
  16. <table id="tt" class="easyui-datagrid" style="width:910px;height:350px"  
  17.        title="參數項列表" iconCls="icon-save"  
  18.        rownumbers="false" pagination="true">  
  19. </table>  
  20.   
  21. <script type="text/javascript">  
  22.   
  23.     $('#tt').datagrid({  
  24.         title: "參數項列表",  
  25.         url: '/getAllParam',  
  26.         pageSize:5,  
  27.           
  28.         columns: [  
  29.             [  
  30.                 {field: 'paramId', title: '參數ID', width: 180, align: "center"},  
  31.                 {field: 'paramName', title: '參數名稱', width: 180, align: "center"},  
  32.                 {field: 'paramLabel', title: '標籤', width: 180, align: 'center'},  
  33.                 {field: 'createTime', title: '創建時間', width: 180, align: "center"}  
  34.             ]  
  35.         ], toolbar: [  
  36.             {  
  37.                 text: '添加',  
  38.                 iconCls: 'icon-add',  
  39.                 handler: function () {  
  40.                     openDialog("add_dialog", "add");  
  41.                 }  
  42.             },  
  43.             '-',  
  44.             {  
  45.                 text: '修改',  
  46.                 iconCls: 'icon-edit',  
  47.                 handler: function () {  
  48.                     openDialog("add_dialog", "edit");  
  49.                 }  
  50.             },  
  51.             '-',  
  52.             {  
  53.                 text: '刪除',  
  54.                 iconCls: 'icon-remove',  
  55.                 handler: function () {  
  56.                     delAppInfo();  
  57.                 }  
  58.             }  
  59.         ]  
  60.     });  
  61.   
  62.     //設置分頁控件  
  63.     var p = $('#tt').datagrid('getPager');  
  64.     p.pagination({  
  65.         pageSize: 5,//每頁顯示的記錄條數,默認爲10  
  66.         pageList: [5, 10, 15],//可以設置每頁記錄條數的列表  
  67.         beforePageText: '第',//頁數文本框前顯示的漢字  
  68.         afterPageText: '頁    共 {pages} 頁',  
  69.         displayMsg: '當前顯示 {from} - {to} 條記錄   共 {total} 條記錄'  
  70.     });  
  71. </script>  
  72. </body>  
  73. </html>  

mapper.xml

[html] view plaincopy
  1. <!-- 分頁查詢-->  
  2.     <select id="selectAllPage" resultMap="BaseResultMap" parameterType="java.util.Map" >  
  3.         select  
  4.         <include refid="Base_Column_List"/>  
  5.         from param_item  
  6.         <include refid="Example_Where_Clause"/>  
  7.         limit #{pageIndex},#{pageSize}  
  8.     </select>  

controller方法

[java] view plaincopy
  1. @RequestMapping(value = "getAllParam")  
  2.   public void getAllParam(HttpServletRequest request, HttpServletResponse response,  
  3.                           @RequestParam(required = false, defaultValue = "1") Integer page, //第幾頁  
  4.                           @RequestParam(required = false, defaultValue = "10") Integer rows, //頁數大小  
  5.                           @RequestParam(required = false, defaultValue = "") String paramName,  
  6.                           @RequestParam(required = false, defaultValue = "") String createTime  
  7.   ) throws IOException {  
  8.       JSONObject params = new JSONObject();  
  9.       params.put("pageSize", rows);  
  10.       params.put("pageIndex", (page-1)*rows);  
  11.       if (StringUtil.notEmpty(paramName)) {  
  12.           params.put("paramName", paramName);  
  13.       }  
  14.       if (StringUtil.notEmpty(createTime)) {  
  15.   
  16.       }  
  17.       List list = paramItemService.getAllItemPage(params);  
  18.       JSONObject result = new JSONObject();  
  19.       result.put("rows", list);  
  20.       result.put("total"11);  
  21.       ResponseUtil.sendJsonNoCache(response, result.toJSONString());  
  22.   }  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章