在SSH框架中,实现 带条件的分页查询 ,不使用ExtJs和Jquery,困扰了一下午了。求解释啊。最好有源码实例。

解决方案 »

  1.   

      public class Page<T> {
        // -- 公共变量 --//
        public static final String ASC = "asc";
        public static final String DESC = "desc";    // -- 分页参数 --//
        protected int pageNo = 1; //第几页
        protected int pageSize = 1; //每页显示的数量
        protected String orderBy = null;
        protected String order = null;
        protected boolean autoCount = true;    // -- 返回结果 --//
        protected List<T> result = Lists.newArrayList(); //查询的结果
        protected long totalCount = -1;//查询数据的总数    // -- 构造函数 --//
        public Page() {
        }
    }
    其他代码就不写了,
    其实就是 你先取出所有的数据得到总数,
    然后根据你的页面和每页显示的数量判断出 要显示的数据是冲多少开始查询,查多少数据。这个hibernate自带的方法
    setFirstResult(int i)重第几个开始查询
    setMaxResults(int i)查几个大概就是这样啦,具体的话 自己慢慢的查资料写把,
    有写东西自己写了 会明白很多东西
      

  2.   

    不是有方法吗?String sql="from RPMS_user user where user.userName=? and user.userPass=?";
    Query query=sessionFactory.getCurrentSession().createQuery(sql);
    query.setParameter(0, user.getUserName());
    query.setParameter(1, user.getUserPass());
                    //还要分页的话
                    query.setMaxResults(5);
            query.setFirstResult((pageNow-1)*5);