Layui_分页

HTML页面

<!--定义一个table表格位置-->

<table id="userTable" lay-filter="userEvent"></table>

<!--定义行操作(这里添加了判定)-->

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>

    {{# if(d.userRole==1){}}

    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" lay-     event="del">删除</a>

    {{# } else if(d.userRole==2){}}

    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">删除</a>

    {{# }}}

</script>

JS代码

layui.use('table',function(){           //这里必须添加依赖table面板

var table =layui.table;

    table.render({

        elem:'#userTable'

        ,url:'/ControlManager/userController/selAllUserInfo'    //controller

        ,page:true

        ,limit:5

        ,limits : [5,10,15]

        ,groups:3

        ,cols: [[//表头

            {field:'userId',title:'ID',width:'20%',align:'center',sort:true}

            ,{field:'userCode',title:'用户名',width:'20%',align:'center'}

            ,{field:'userRole',title:'角色',width:'30%',align:'center',templet:function(d){

                 if (d.userRole=="1"){

                        return "管理员"

                  }else {

                       return "普通用户"

                }

             }}

            ,{field:'operate',title:'操作',width:'30%',toolbar:'#barDemo',align:'center',templet:'#barDemo'}

       ]]

,done:function () {              //加载完成的回调函数

          layer.msg("数据加载完成...",{icon:1,time:1500});

}

});

});

Controller层

   

@ResponseBody

    @RequestMapping(value = "/objectMethod" )

    public Object objectMethod(@RequestParam("page") String page1,@RequestParam("limit")String limit1){

        int page = Integer.valueOf(page1);             //分页参数,根据数据库不同进行改变(这里是Oracle数据库)

        int limit = Integer.valueOf(limit1);             

        int before = limit * (page -1) +1;

        int after = page * limit;

        List<Object> userList = objectService.selAllObject(); //查询要显示的信息集合

        HashMap<String,Object> objMap = new HashMap<String,Object>(); //HashMap集合,用于返回json数据

        objMap.put("code",0); //code,可用于前端判断

        objMap.put("msg", ""); //类似code,msg可赋予字符串,用作提示;

        objMap.put("count",userService.countUser());      //调用方法查询全部

        Object arry = JSONArray.toJSON(userList);

        objMap.put("data",arry);

        return JSONArray.toJSONString(objMap);

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值