Java分页操作

HQL 语句
/**
	 * <p>Method :queryEstInfoList
	 * <p>Description : 股权查询列表
	 *
	 * @param estQueryBean
	 * @param pageNum
	 * @param pageSize
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<FrkGsjQyjgdjxx> queryEstInfoList(final FrkGsjQyjgdjxx estQueryBean,
			final int pageNum, final int pageSize) {
		return (List<FrkGsjQyjgdjxx>) this.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session)throws HibernateException, SQLException {
				StringBuffer queryHQL = new StringBuffer();
				queryHQL.append("from FrkGsjQyjgdjxx where 1 = 1 ");
				List<Object> params = new ArrayList<Object>();
				if(estQueryBean!=null)
				{
					if(StringUtils.isNotBlank(estQueryBean.getZzjgdm())){
						queryHQL.append(" and zzjgdm = ? ");
						params.add(estQueryBean.getZzjgdm());
					}
					if(StringUtils.isNotBlank(estQueryBean.getQyjgmc())){
						queryHQL.append(" and qyjgmc like ? ");
						params.add("%" + estQueryBean.getQyjgmc() + "%");
					}
					if(StringUtils.isNotBlank(estQueryBean.getZch())){
						queryHQL.append(" and zch = ? ");
						params.add(estQueryBean.getZch());
					}
					if(StringUtils.isNotBlank(estQueryBean.getFddbrxm())){
						queryHQL.append(" and fddbrxm like ? ");
						params.add("%" + estQueryBean.getFddbrxm() + "%");
					}
				}
				Query query = session.createQuery(queryHQL.toString());
				if (params != null) {
					for (int i = 0; i < params.size(); i++) {
						query.setParameter(i, params.get(i));
					}
				}
				
				if (pageNum > 0) {
					query.setMaxResults(pageSize);
					query.setFirstResult((pageNum - 1) * pageSize);
				}
                return query.list();
			}
		});
	}

/**
	 * <p>Method :queryEstInfoCount
	 * <p>Description : 股权查询记录数
	 *
	 * @param estQueryBean
	 * @return 
	 */
	@Override
	public Integer queryEstInfoCount(final FrkGsjQyjgdjxx estQueryBean) {
		return ((Integer) this.getHibernateTemplate().execute(new HibernateCallback() {
			@SuppressWarnings("unchecked")
			public Object doInHibernate(Session session)throws HibernateException, SQLException {
				StringBuffer queryHQL = new StringBuffer();
				queryHQL.append("select count(*) from FrkGsjQyjgdjxx where 1 = 1 ");
				List<Object> params = new ArrayList<Object>();
				if(estQueryBean!=null)
				{
					if(StringUtils.isNotBlank(estQueryBean.getZzjgdm())){
						queryHQL.append(" and zzjgdm = ? ");
						params.add(estQueryBean.getZzjgdm());
					}
					if(StringUtils.isNotBlank(estQueryBean.getQyjgmc())){
						queryHQL.append(" and qyjgmc like ? ");
						params.add("%" + estQueryBean.getQyjgmc() + "%");
					}
					if(StringUtils.isNotBlank(estQueryBean.getZch())){
						queryHQL.append(" and zch = ? ");
						params.add(estQueryBean.getZch());
					}
					if(StringUtils.isNotBlank(estQueryBean.getFddbrxm())){
						queryHQL.append(" and fddbrxm like ? ");
						params.add("%" + estQueryBean.getFddbrxm() + "%");
					}
				}
				Query query = session.createQuery(queryHQL.toString());
				if (params != null) {
					for (int i = 0; i < params.size(); i++) {
						query.setParameter(i, params.get(i));
					}
				}
				
				List list = query.list();
				if (list != null && 0 < list.size()) {
                    Object[] result = list.toArray();
                    return new Integer(result[0].toString());
                } else {
                    return 0;
                }
			}
		})).intValue();
	}


你可能感兴趣的:(java 分页)