<%@ 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;
}