有个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;
}