利用Java如何实现前台与后台页面分页

今天就跟大家聊聊有关利用Java如何实现前台与后台页面分页,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

站在用户的角度思考问题,与客户深入沟通,找到青山网站设计与青山网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、虚拟空间、企业邮箱。业务覆盖青山地区。

先上图吧,大致如图,也就提供个思路(ps:使用了SSH框架) 

利用Java如何实现前台与后台页面分页

前台JSP页面

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>  



 数据交易猫 
  



    
    

需求列表

筛选:按

悬赏积分:${price}

需求描述:${requirementDescription}



action

 //查询需求列表
 public String queryRequirListByPage(){
  int pageSize=5;//每页记录
  String hql="select r from Requirement r where r.reStatus !=2 ";
  if(sortValue == null || sortValue.length() <= 0){
   hql=hql+"order by r.publishDatetime desc";
   ActionContext.getContext().put("sortValue", "publishDatetime"); //当前页码条件
   session.put("sessionReqSortValue","publishDatetime");
  }else{
  hql=hql+"order by r."+sortValue+" desc";
   ActionContext.getContext().put("sortValue", sortValue); //当前页码条件
   session.put("sessionReqSortValue",sortValue);
  }
  long icount=requirementService.countAllRe();//总记录数
  long allPage;//总页数
  //判断是否能整除,能则直接,不能则+1;
  if((icount%pageSize)==0){
   allPage=icount/pageSize;
  }
  else{
   allPage=(icount/pageSize)+1;
  }
  System.out.println("总记录:"+icount+";总页数:"+allPage+";当前页码:"+pageNo);
  List requiList=requirementService.queryByPage(hql, pageNo, pageSize);
  ActionContext.getContext().put("requiList", requiList);//需求列表
  ActionContext.getContext().put("icount", icount);//总记录数
  ActionContext.getContext().put("allPage", allPage);//总页数
  ActionContext.getContext().put("currentPage", pageNo); //当前页码
  session.put("sessionCurrentPage", pageNo);
  return "requireContent";

 }

service

  public long countAllRe() {
  return requirementDao.countAllRe();
 }
  public List queryByPage(String hql, int pageNo, int pageSize) {
  return requirementDao.queryByPage(hql, pageNo, pageSize);
 }

dao

 //这里可能会报错,就是直接查询数据列表(使用了SSH)
 public long countAll() {
  List<?> l = getSession().createQuery("select count(*) from "
    + clazz.getSimpleName()).list();
  if (l != null && l.size() == 1 )
  {
   return (Long)l.get(0);
  }
  return 0;
 }
 public List queryByPage(String hql, int pageNo, int pageSize) {
  return getSession()
    .createQuery(hql)
    .setFirstResult((pageNo - 1) * pageSize)
    .setMaxResults(pageSize)
    .list();
 }

看完上述内容,你们对利用Java如何实现前台与后台页面分页有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


本文标题:利用Java如何实现前台与后台页面分页
文章路径:http://myzitong.com/article/iigige.html