• 玩转Web之easyui(一)-----easy ui datagird 分页


    easy ui 中数据表格的分页其实是很简单的,分页是在数据表格可以正常显示数据的基础上进行的,在这里给出servlet的代码,其中selectAll()方法是从数据库中提取所有数据,

    分页的一种思路是:从数据表中取出所有数据,然后根据分页的要求取出对应的数据。

    package thejavabean;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import net.sf.json.JSONArray;
    
    public class Table_info extends HttpServlet {
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    
    		try {
    			response.setContentType("text/html");
    			response.setCharacterEncoding("UTF-8");
    			PrintWriter out = response.getWriter();
    			String page = request.getParameter("page"); // 当前页数
    			String rows = request.getParameter("rows"); // 每页显示行数  
    			
    			List<Student> allList=selectAll();   //获取所有数据
    			int p=Integer.parseInt(page);    
    			int r=Integer.parseInt(rows);
    			int begin=(p-1)*r;  //当前页开始项
    			int num=begin;
    			int count=r;
    			List<Student> list=new ArrayList();
    			System.out.println();
    			while(count>0&&num<allList.size()){
    				list.add(allList.get(num)); 
    				num++;
    				count--;
    			}
    			int total=selectAll().size();
    			String json = "{"total":"+total+" , "rows":"+JSONArray.fromObject(list).toString()+"}";
    		    
    			response.getWriter().write(json.toString());
    			out.flush();
    			out.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		
    	}
        public List<Student> selectAll() throws SQLException{
        	StudentManage sm=new StudentManage();
    		return sm.selectAll("");
        	
        }
    	public void doPost(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    		this.doGet(request, response);
    		
    	}
    
    }
    


     

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    http headers总结
    golang跨域配置
    Kafka中topic的Partition,Kafka为什么这么快,Consumer的负载均衡及consumerGroup的概念
    kafka partition(分区)与 group
    RocketMQ从部署到应用(Golang)
    Codeforces Round #706 (Div. 2)
    关于平衡树
    具体数学 第三章 整值函数
    FFT&NTT&多项式全家桶
    省选测试15
  • 原文地址:https://www.cnblogs.com/dingxiaoyue/p/4931825.html
Copyright © 2020-2023  润新知