layer分页

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript" src="<%=basePath %>js/jquery-1.8.0.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath %>js/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath %>js/layui-v2.5.5/layui/layui.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath %>js/layui-v2.5.5/layui/css/layui.css" charset="utf-8">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>layer</title>
<style>
</style>
</script>
</head>
<body>
<table id="demo" lay-filter="test"></table>
<script charset="utf-8">
layui.use('table', function(){
  var table = layui.table;
  //第一个实例
  table.render({
    elem: '#demo'
    ,height: 312
    ,url: 'user/toList.do' //数据接口
    ,page:true //开启分页
    ,limit: 10
    ,method:"post"
    ,cols: [[ //表头
      {field: '_name', title: '用户名', width:80}
      ,{field: '_workId', title: '工号', width:80, sort: true}
      ,{field: '_email', title: '邮箱', width:80} 
      ,{field: '_lastlogintime', title: '最后登录时间', width: 177}
      ,{field: '_logintimes', title: '登录次数', width: 80, sort: true}
    ]]
  });
});
</script>
</body>
</html>

@RequestMapping(value="/toList.do")
	@ResponseBody
	public JSONObject toList(HttpServletRequest request,Integer page,Integer limit) throws Exception {
		return userService.toList(request,page, limit);
	}
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public JSONObject toList(HttpServletRequest request,Integer page,Integer limit) throws Exception {
		String search = res.getParameter(request, "search", "");
		String hql = "from _TUser where _type = 1 and _is_hidden = 0 order by _inputdate desc";
		if(!"".equals(search)){
			hql = "from _TUser where _name like '%"+ search +"%' or _workId like '%"+ search +"%' order by _name,_inputdate desc";
		}
		// 获得总数
		int total = DBUtils.getTotal("_TUser");
		// 当前页
		page = page == null || page <= 0 ? 1 : page;
		// 每页显示条数
		List<_TUser> list = (List<_TUser>) systemBaseDAO.findAll(hql, limit, page);
		// 返回的数据list放入rows
		
		
		JSONObject obj =new  JSONObject();
		obj.put("code", 0);
		obj.put("count", total);
		obj.put("msg", "");
		obj.put("rows", list);
		obj.put("total", list == null ? 0 : total);
		obj.put("data",list);
		return obj;
	}
	
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值