请各位大侠给出完整的分页源代码,谢谢!
解决方案 »
- 一个方法 return 就有错误
- 大家都用什么工作流作开发?
- 谁能提供J2EE.jar包下载,急~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 帮忙看下关于HQL查询的时候类型转换出错!急哈
- ibatis使用复杂类型集时总出错!!麻烦你给看看!!
- hibernate多对一问题
- 关于使用jdom后xml加载到dom后如何提取相应的数据问题
- 用POI操作Excel文件时,面对函数Cell概怎么处理? (在线给分)
- 两个题目,200分!!!
- windows下修改eclipse的默认编码的方法
- 请教一个checkbox问题
- 一段代码问题
private int totalRows;// 总行数
private int pageSize = page_size;// 每页显示的行数
private int currentPage;// 当前页号
private int totalPages;// 总的页数
private boolean hasNext;// 是否还有下一页
private boolean hasPrevious;// 是否还有上一页
private Collection<Integer> indexList;// 页码的集合
public NewsServices newsServices; public int getTotalRows() {
return totalRows;
} public NewsServices getNewsServices() {
return newsServices;
} public void setNewsServices(NewsServices newsServices) {
this.newsServices = newsServices;
} public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
} public int getPageSize() {
return pageSize;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize;
} public int getCurrentPage() {
return currentPage;
} public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
} public boolean isHasNext() {
return hasNext;
} public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
} public boolean isHasPrevious() {
return hasPrevious;
} public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
} public Collection<Integer> getIndexList() {
ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = 1; i <= getTotalPages(); i++)
result.add(new Integer(i));
return indexList;
} public void setIndexList(Collection<Integer> indexList) {
this.indexList = indexList;
} public static int getPage_size() {
return page_size;
} public int getTotalPages() {
return totalPages;
} public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
} public int getStartRow() {
if (getCurrentPage() == 1)
return 0;
else
return (getCurrentPage() - 1) * pageSize;
} public void first() {
currentPage = 1;
} public void last() {
currentPage = totalPages;
} /*
* public void previous(){ if(currentPage==1) return; else currentPage--;
* } public void next(){ if(currentPage<totalPages) currentPage++; }
*/
public Collection<?> pageList(String countHsql, String queryHsql) { try {
int totalRows = this.newsServices.getRows(countHsql);// 总行数
this.setTotalRows(totalRows);
int totalPages = totalRows / pageSize;// 总 页数
int mod = totalRows % pageSize;
if (mod > 0)
totalPages++;
if (currentPage == 0 || currentPage < 1) {
first();
}
if (currentPage > totalPages)
last();
if (currentPage >= 1 && currentPage <= totalPages)
hasNext = true;
if (currentPage > 1 && currentPage < totalPages)
hasPrevious = true;
return this.newsServices.getWithPage(queryHsql, getStartRow(),
currentPage*page_size);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}不知道你用不用的到
然后在jsp页面你会用到的struts分页相关标签:<logic:iterate id="User" scope="request" name="Userlist"></logic:iterate>这个是做遍历用;<logic:greaterThan value="1" name="currentpage"></logic:greaterThan>做比较用,不能让索引超出范围
* return @pagenum 第几页
* return @pageSize 每页显示几行
*/
public List FindAllUserBypage(final int pagenum,final int pageSize)
{
return (List)super.getHibernateTemplate().execute(new HibernateCallback()
{ public Object doInHibernate(Session session) throws HibernateException, SQLException {
String hql="from UserInfo u order by u.id asc";
Query query = session.createQuery(hql);
int result = pageSize*(pagenum-1);
query.setFirstResult(result);
query.setMaxResults(pageSize);
List list = query.list();
return list;
}
}
);
这个类必须继承:HibernateDaoSupport
jsp+struts2+SQLServer进行提问?请各位大侠能够完整的代码,比如jsp代码,Action代码,server怎么读取数据,大家帮帮忙,谢谢!
其它形实的分面拿来改改即可