Struts中后台分页查询代码

 

简单的后台代码, 分页查询。

 

//根据姓名和联系人类型查找联系人信息;
	public ActionForward selectTypeIdAndPersonName(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
		String check=request.getParameter("check");
		String name=null;
		if("button".equals(check)){
			name=request.getParameter("txtName");
		}else{
			name=new String(request.getParameter("txtName").getBytes("ISO-8859-1"),"GBK");
		}
		String id=request.getParameter("txtTypeId");
		Long typeid=new Long(0);
		int page=1;
		
		if(id!=null && !"".equals(id)){
			typeid=Long.parseLong(id);
		}
			
		//得到传过来的类型;
		String type=request.getParameter("type");
		List<Personmessagetype> list1=ims.selectAll();
		request.setAttribute("PersonMessageType", list1);
			
		//得到总记录数;
		int sum=ims.getSum(typeid,name);
		
		//把总记录数除以显示的条数,得到总页数;
		int sumPage=sum/8==0?sum/8:sum/8+1;
		
		//判断是上一页还是下一页;
		if("shouye".equals(type)){
			page=1;
		}else if("weiye".equals(type)){
			page=sumPage;
		}else if("shangyiye".equals(type)){
			page=page>=1?page-1:1;
		}else if("xiayiye".equals(type)){
			page=page<=sumPage?page+1:sumPage;
		}else{
			System.out.println("type为空");
			page=1;
		}
		
		request.setAttribute("sumPage",sumPage);
		request.setAttribute("currPage", page);
		request.setAttribute("sum", sum);
		
		List<Personmessage> list=ims.selectTypeIdandPersonMessageName(typeid,name,page);
		//得到联系人集合;
		request.setAttribute("PMessageList", list);
		
		//转发;
		return new ActionForward("/view/selectLianXiRen.jsp");
	}

 

你可能感兴趣的:(struts)