SSM框架+PageHelper实现EasyUI分页

SSM框架实现EasyUI分页

注意:本文章不提供如何搭建SSM框架
下面是我搭建所使用的教程:
使用idea搭建SSM:https://www.cnblogs.com/hackyo/p/6646051.html

代码块

HTML:

<body class="easyui-layout">
        <div data-options="region:'center',title:'Center'">
            <table id="list_data" class="easyui-datagrid" style="width:100%;height:auto;">
                <thead>
                    <tr>
                        <th field="name" width="100">姓名</th>
                        <th field="address" width="100">地址</th>
                        <th field="sex" width="100">性别</th>
                        <th field="idCard" width="100">身份证</th>
                        <th field="birth_Date" width="100">出生日期</th>
                        <th field="issue_Date" width="100">发证日期</th>
                        <th field="permit_Type" width="100">准驾类型</th>
                        <th field="expiration_Date" width="100">有限日期</th>
                        <th field="carNum" width="100">车牌号</th>
                        <th field="id" width="100">id</th>
                    </tr>
                </thead>
            </table>
        </div>
    </body>
    <script>
    //自动发请求到url,并把返回的数据自动填入
        $('#list_data').datagrid({
            url: 'http://localhost:8080/veigar/testJson',
            dataType:'JSONP',
            rownumbers: true,
            singleSelect: true,
            pagination: true,
            idField: 'id',
            fitColumns: true,
            fit: true,
            nowarp: false,
            border: false,
            pageSize: 5,
            pageList: [5, 10],
        });
    </script>

Controller:
@ResponseBody会返回一个json,而不会直接去跳转到某个页面。
而EasyUI只需要接收两个参数:total和rows,自己会直接做分页的事情。
注意这里除了map,也可以将total和rows封装成一个类来返回。

@RequestMapping("/testJson")
@ResponseBody
public Map<String,Object> testJson(@RequestParam int page, int rows) throws IOException {
        /*
         * page:第几页
         * rows:每页多少条数据
         * 进行count查询。第三个參数设为true
         */
        PageHelper.startPage(page, rows, true);
        //执行查询所有对象
        List<Driver> list  = this.userService.selectAllDR();
        //将list传入PageInfo
        PageInfo<ComplainRecord> info = new PageInfo(list);
        //以下list是已经做好分页的list
        list =info.getList();
        //获取总数
        long count = info.getTotal();
        //前台接收到的json,map会自动转为json,可以在F12控制台查看
        Map<String,Object> map = new HashMap<>();
        map.put("total",count);
        map.put("rows",list);
        return map;
    }

Interface:

@Select("SELECT * FROM driver")
public List<Driver> selectAllDR();

Pagehelper所需要的依赖。
http://mvnrepository.com/artifact/com.github.pagehelper/pagehelper 可以直接去库下载。
还是建议使用maven项目。

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.2</version>
</dependency>
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值