输出导航条 博客分类: hibernate HibernateJSP
程序员文章站
2024-03-16 09:57:34
...
/** * <p> * 输出导航条 * </p> * * @author chenwei * @param ses:org.hibernate.Session对象 * @param HQLsql:HQL语句 * @param page:当前页数 * @param pageSize:每页的记录数 * @param webpage:显示的页面[若带多个参数,可以这样写 a.jsp?r=XX&t=xx ] * @return java.lang.String * @throws SessionFactoryException */ public String turnpageBar(Session ses, String HQLsql, int page, int pageSize, String webpage) { // 总页数 int pageCount = 0; // 总记录数 int recordCount = 0; // 是否带多个参数 boolean moreParam = webpage.indexOf("?") == -1 ? false : true; StringBuffer scriptStr = new StringBuffer(); scriptStr.append("<script language=\"javascript\">"); scriptStr.append("function change(objid){"); scriptStr.append("var p=document.getElementById(objid).value;"); if (!moreParam) scriptStr.append("window.location=\"" + webpage + "?page=\"+p;"); else scriptStr.append("window.location=\"" + webpage + "&page=\"+p;"); scriptStr.append("}</script>"); StringBuffer sb = new StringBuffer(scriptStr.toString()); Transaction tran = null; tran = ses.beginTransaction(); java.util.List list = ses.createQuery(HQLsql).list(); tran.commit(); ses.close(); if (list != null && list.size() > 0) recordCount = list.size(); if (recordCount == 0) return "<font color=\"red\">没有记录</font>"; else { pageCount = recordCount % pageSize == 0 ? recordCount / pageSize : recordCount / pageSize + 1; sb.append("第" + page + "页/共" + pageCount + "页 "); sb.append("共" + recordCount + "条记录 每页" + pageSize + "条记录 "); if (!moreParam) sb.append("<a href=\"" + webpage + "?page=1\">首页</a> "); else sb.append("<a href=\"" + webpage + "&page=1\">首页</a> "); if (page > 1) { if (!moreParam) sb.append("<a href=\"" + webpage + "?page=" + (page - 1) + "\">上一页</a> "); else sb.append("<a href=\"" + webpage + "&page=" + (page - 1) + "\">上一页</a> "); } else sb.append("上一页 "); if (page < pageCount) { if (!moreParam) sb.append("<a href=\"" + webpage + "?page=" + (page + 1) + "\">下一页</a> "); else sb.append("<a href=\"" + webpage + "&page=" + (page + 1) + "\">下一页</a> "); } else sb.append("下一页 "); if(!moreParam) sb.append("<a href=\"" + webpage + "?page=" + pageCount + "\">尾页</a> "); else sb.append("<a href=\"" + webpage + "&page=" + pageCount + "\">尾页</a> "); StringBuffer select = new StringBuffer("转到第"); select.append("<select id=\"sel\" onchange=\"change('sel')\">"); for (int i = 1; i <= pageCount; i++) { if (page == i) select.append("<option value=\"" + i + "\" selected=\"selected\">" + i + "</option>"); else select.append("<option value=\"" + i + "\">" + i + "</option>"); } select.append("</select>页"); sb.append(select.toString()); return sb.toString(); } }
推荐阅读
-
输出导航条 博客分类: hibernate HibernateJSP
-
批量删除 博客分类: hibernate 批量删除
-
关于配置 博客分类: hibernate HibernateSQLMyeclipseMicrosoftJDBC
-
关于org.hibernate.NonUniqueObjectException 博客分类: hibernate HibernateBean
-
关于org.hibernate.NonUniqueObjectException 博客分类: hibernate HibernateBean
-
批量删除 博客分类: hibernate 批量删除
-
分页查询 博客分类: hibernate 分页查询
-
输出导航条 博客分类: hibernate HibernateJSP
-
分页查询 博客分类: hibernate 分页查询
-
关于配置 博客分类: hibernate HibernateSQLMyeclipseMicrosoftJDBC