ssh2框架以及分页留存

有个ssh2 架构已经做好了,花了我5小时。。。

在115网盘 账号为11366***@qq.com , ssh.zip里面

ps:其实大项目 ,很多人参与的,用ssh2还是挺好,挺正规的


反正以后要用的。先记录下,以后懒得想
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
	/**
	 * 返回queryString查询返回的记录数
	 * 
	 * @param queryString
	 * @param values
	 * @return Long
	 */
	public Long getTotalItems(final String queryString,
			final Object[] values) {
		QueryTranslatorImpl queryTranslator = new QueryTranslatorImpl(queryString, queryString, 
		java.util.Collections.EMPTY_MAP, (SessionFactoryImplementor) getSessionFactory());
		queryTranslator.compile(java.util.Collections.EMPTY_MAP, false);
		final String sql="select count(*) from (" + queryTranslator.getSQLString() + ") tmp_count_t"; 
		
		SQLQuery query = getSession().createSQLQuery(sql);
		if (values != null) {
			for (int i = 0; i < values.length; i++) {
				query.setParameter(i, values[i]);
			}
		}
		return BigUtil.bigLongIsNull((BigDecimal)query.uniqueResult());
	
	}



@SuppressWarnings("unchecked")
	public PagingBean getAllType(PagingBean pb, String party) throws Exception {

		HttpSession session = ServletActionContext.getRequest().getSession();
		String hql = "";
		if (MyStrUtil.isBlank(party)) {
			// 跳转到登录页面

			hql = "from TclMaintainKnowall where isalive=1   order by id desc";
		} else {
			hql = "from TclMaintainKnowall where isalive=1 and userid='"
					+ party + "'   order by id desc";
		}

		int totalItems = getTotalItems(hql, null).intValue();
		int totalPage = PagingBean.countTotalPage(pb.getPageSize(), totalItems);
		int offset = PagingBean.countOffset(pb.getPageSize(), pb.getStart());
		if (offset < 0) {
			offset = 0;
		}
		int currentPage = PagingBean.countCurrentPage(pb.getStart());
		List<TclMaintainKnowall> list = null;
		try {
			Query query = getSession().createQuery(hql);
			query.setFirstResult(offset);
			query.setMaxResults(pb.getPageSize());
			list = query.list();
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		pb.setSize(pb.getPageSize());
		pb.setTotalItems(totalItems);
		pb.setTotalPage(totalPage);
		pb.setList(list);
		pb.setCurrentPage(currentPage);
		return pb;
	}




/**
* 计算总页数
* @param pageSize 每页记录数
* @param allRow 总的记录数
* @return 总页数
*/
public static int countTotalPage(final int size,final int totalItems)
{
int totalPage=totalItems%size==0?totalItems/size:totalItems/size+1;
return totalPage;
}

/**
* 计算当前页开始的记录的号
* @param pageSize  每页显示数
* @param currentPage 当前第几页
* @return 当前页开始的记录号
*/

public static int countOffset(final int size,final int currentPage)
{
final int offset=size*(currentPage-1);
return offset;
}
/**
* 判断当前页是否为0,如果为0 则将其设置为1
* @param page 从表单传入的参数
* @return
*/
public static int countCurrentPage(int page)
{
final int curPage=(page==0?1:page);
return curPage;
}


反正以后要用的。先记录下,以后懒得想
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值