jsp
<div id="feiye">
<center>当前是第${currentPage}页,共有${totalPage}页
<a href="yrecordinfo.action?currentPage=1" >首页</a>
<s:if test="%{currentPage>1}"><a href="yrecordinfo.action?currentPage=${currentPage-1}" >上一页</a>
<a href="yrecordinfo.action?currentPage=${currentPage-1}" >${currentPage-1}</a></s:if>
<a href="yrecordinfo.action?currentPage=${currentPage}" >${currentPage}</a>
<s:if test="%{totalPage>currentPage}"><a href="yrecordinfo.action?currentPage=${currentPage+1}" >${currentPage+1}</a>
<a href="yrecordinfo.action?currentPage=${currentPage+1}" >下一页</a></s:if>
<a href="yrecordinfo.action?currentPage=${totalPage}" >尾页</a></center>
</div>
action
private String num;// 查出了多少条 private List<YRecordInfo> recordlist;// 列表页 private String totalPage;//总页数 private String currentPage ;// 当前页, private String pageSize="10";//一页显示多少/*** * 分页 * 分析, * http://127.0.0.1:8080/aaa/main/yrecordinfo.action?currentPage=1 * * 1. 根据 条件 得到一个 总数, 通过计算 ,得到总页数、 * 2. 根据 分页的 得到 自己 需要的那一页的 条数 */ private void feiye() { YRecordInfoDao dao = new YRecordInfoDao(); if(currentPage==null){ currentPage="1"; } List<YRecordInfo> listtemp= dao.search(Integer.parseInt( currentPage),Integer.parseInt( pageSize)); setNum(listtemp.size()+""); setRecordlist(listtemp);
int totalSize = dao.search().size();// 总数量(只是根据时间查询的)//1. 根据 条件 得到一个 总数, 通过计算 ,得到总页数、
int mod = totalSize % Integer.parseInt(pageSize);if (mod == 0) {totalPage = totalSize / Integer.parseInt(pageSize) + "";} else{totalPage = totalSize / Integer.parseInt(pageSize) + 1 + "";}setTotalPage(totalPage);} dao//2. 根据 分页的 得到 自己 需要的那一页的 条数
/*** * ** * 查询多条数据 * @param currentPage //第几页 * @param pageSize // //每页多少条数据 * 分析: * 1得到总条数, * 2 总共分几页 * 3根据 第几页 算出 开始索引 * @return */ public List<YRecordInfo> search(int currentPage,int pageSize) { //构建Session工具对象 Session s=HibernateSessionFactory.getSession(); //SELECT * FROM [Y_RecordInfo] where BeginTime between '2017-04-01 00:00:00' and '2017-05-02 23:59:59' order by PhoneId //HQL语句,有3个参数,参数的序号从0开始 String hql="from YRecordInfo where BeginTime between ? and ? order by BeginTime desc"; // //构建查询对象 Query q=s.createQuery(hql); //设置查询参数 q.setString(0, "2017-04-21 10:06:39"); q.setString(1, "2017-10-21 10:06:39"); // q.setInteger(2, startNum);//从第几条开始 int startRow=(currentPage-1)*pageSize; q.setFirstResult(startRow); q.setMaxResults(pageSize); return q.list(); }