公司要我用MyEclipse开发SSH框架的结构,并且开发jsp页面的分页,请问大家如何开发,我接触的少,没点头绪,很急呀,有详细代码更好

解决方案 »

  1.   

    createQuery("from User").setFirstResult(0).setMaxResults(10).list();更多的讲解参考
    http://family168.com/oa/tech/hibernate.html#d4e740
      

  2.   

    package xxxx.page;import java.util.List;/***
     * 封装分页结果集
     * @author [email protected]
     * @since 2009-5-19
     *
     */
    public class Pagetor {

    //结果集 private List pageList;
    //当前页 private int pageNo = 1;
    //总页数 private int totalCount;
    //每页最多显示条数 private int pageSize = 10; public List getPageList() {
    return pageList;
    }
    public void setPageList(List pageList) {
    this.pageList = pageList;
    } public int getPageNo() {
    return pageNo;
    }
    public void setPageNo(int pageNo) {
    this.pageNo = pageNo;
    }
    // 总页数 public int getPageSum() {

    return totalCount / pageSize + ((totalCount % pageSize) == 0?0:1) ;
    } public int getPageSize() {
    return pageSize;
    }
    public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
    }
    public int getTotalCount() {
    return totalCount;
    }
    public void setTotalCount(int totalCount) {
    this.totalCount = totalCount;
    }
    }
    ///查询
    /*
     * 实现分页
     * (non-Javadoc)
     * @see com.coshine.cms.service.PageServiceBase#findByConditions(int, int, java.util.Map, boolean)
     */
    public List findByConditions(int pageNo, int pageSize, Map conditions, boolean isCount) {

    DetachedCriteria criteria = DetachedCriteria.forClass(CmsNewsCategory.class);

    if(conditions!=null){
    String ncName = (String) conditions.get("ncName");
    Long ncParentId = (Long) conditions.get("ncParentId");


    if(ncParentId!=null){
    criteria.add(Restrictions.eq("parentCmsNewsCategory.ncId", ncParentId));
    }




    }
    if(isCount){
    criteria.setProjection(Projections.rowCount());
    return cmsNewsCategoryDAO.findByCriteria(criteria);
    }


    return cmsNewsCategoryDAO.findByCriteria(criteria, pageNo, pageSize);
    }
      

  3.   

    //分页封装/*
     * (non-Javadoc)
     * @see com.coshine.cms.iservice.PagetorService#pagetor(int, int, java.util.Map)
     */
    public Pagetor pagetor(int pageNo, int pageSize, Map conditions) {
    Pagetor pagetor = new Pagetor();
    //验证页面大小
    if (0 >= pageSize) {
    pageSize = 10;
    }
    pagetor.setPageSize(pageSize);
    //取得总页数
    List countList = findByConditions(pageNo, pageSize, conditions, true);
    pagetor.setTotalCount(Integer.parseInt((countList.get(0).toString())));
    //验证第几页
    if(pageNo > pagetor.getPageSum() ){
    pageNo = pagetor.getPageSum();
    }
    if (0 >= pageNo) {
    pageNo = 1;
    }
    pagetor.setPageNo(pageNo);
    //取得结果集
    List list = findByConditions(pageNo, pageSize, conditions, false);
    pagetor.setPageList(list);
    return pagetor;
    }