【Servlet】【ajax】分页显示

来源:互联网 发布:php注册登录 编辑:程序博客网 时间:2024/06/05 06:30

使用了layui的插件,和jQuery,使用时需要导入

-------------页面上的主要代码------------------

<script>$(function() {Count_xl();//获取总数ShowEepByPage(1,10);//第一次调用,可以不写});function Count_xl() {$.ajax({url:"GetEmpCountServlet",//获取记录总数dataType : "text",success : function(data) {layui_xl(data*1);}});}function layui_xl(count_xl) {layui.use(['laypage', 'layer'], function(){  var laypage = layui.laypage  ,layer = layui.layer;//  laypage.render({    elem: 'demo7'    ,count: count_xl    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']    ,jump: function(obj){      console.log(obj);      ShowEepByPage(obj.curr,obj.limit);//调用分页查询    }  });});}function ShowEepByPage(pageCount,pageSize) {var $tbody = $("#tbody");$tbody.empty();$.ajax({url : "ShowEmployeeServlet",//分页查询data:{"pageCount":pageCount,"pageSize":pageSize},type : "post",dataType : "json",success : function(data) {$.each(data,function(i, josn) {var str = "<tr>";str += "<td>" + josn.empId+ "</td>";str += "<td>"+ josn.empUserName+ "</td>";str += "<td>" + josn.empRelName + "</td>";str += "<td>"+ josn.empBirthday+ "</td>";str += "<td>"+ josn.empDeptName+ "</td>";str += "<td>" + josn.empId+ "</td>";str += "<td>" + josn.empState+ "</td>";str += "<td class='image'><img src='"+josn.empHead+"' width='40px' height='40px' /></td>";str += "<td><a href='javascript:void(0)' class='tablelink' onclick='openShow("+ josn.empId+ ")'>查看</a> <a href='javascript:void(0)' class='tablelink' onclick='delEmployee("+ josn.empId+ ")'>删除</a></td>";str += "</tr>";$tbody.append(str);});}});}</script>


--------------Servlet返回的数据为JSON数据----主要代码段为--------------


request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");//ajax直接访问不经过过滤器,需要手动设置编码格式
List<Employee> employeeList = userBiz.showEmployeeByPage(pageCount,pageSize);JsonConfig jsonConfig = new JsonConfig();jsonConfig.registerJsonValueProcessor(java.util.Date.class, new JsonDateValueProcessor());JSONArray jsonArray = JSONArray.fromObject(employeeList,jsonConfig);response.getWriter().write(jsonArray.toString());

原创粉丝点击