java吧 关注:1,296,978贴子:12,834,285
  • 12回复贴,共1

springmvc+spring+mybatis分页问题

只看楼主收藏回复

这是主要的代码
Controller:
@RequestMapping("toDownLoad")
public String toDownLoad(HttpServletRequest request,Page page){
int count = this.pageService.findUploadFileCounts(SQLConstant.SELECT_UPLOAD_FILE_TOTAL_COUNT);
int perPageSize = page.getPerPageSize()==0?3:page.getPerPageSize();
int currentPageNum = page.getCurrentPageNum()<=0?1:page.getCurrentPageNum();
int totalPageNum = 0;
if(count%perPageSize==0){
totalPageNum = count/perPageSize;
}else{
totalPageNum = count/perPageSize+1;
}
int firstOne = (currentPageNum-1)*perPageSize;
Page page2 = new Page();
page2.setTotalCount(count);
page2.setPerPageSize(perPageSize);
page2.setCurrentPageNum(currentPageNum);
page2.setTotalPageNum(totalPageNum);
page2.setFirstOne(firstOne);
List<UpDownLoadFile> files = this.pageService.findEntityByPage(page2, SQLConstant.SELECT_File_BY_PAGE);
page2.setList(files);
System.out.println(files);
request.setAttribute("page", page2);
return "file/download";
}
=====================================================================
public class Page {
private int totalCount;//总记录数 --从数据库中查询
private int currentPageNum;//当前第几页--biyou
private int totalPageNum;//总共多少页--计算
private int perPageSize;//每页记录条数--自定义
private int firstOne;//每页的第一条记录
private List list;
// getter ,setter
======================================================================
<body>
<table>
<tr>
<td>文件名</td>
<td>操作</td>
</tr>
<c:forEach items="${page.list}" var="f">
<tr>
<td>${f.fileName }</td>
<td>
<a href="${pageContext.request.contextPath }/mvc/download?fileName=${f.fileName}&&filePath=${f.filePath}">下载</a></td>
</tr>
</c:forEach>
</table>
<c:if test="${page.currentPageNum==1 }">
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.totalPageNum}">尾页</a>&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.currentPageNum+1}">下一页</a>&nbsp;&nbsp;
</c:if>
<c:if test="${page.currentPageNum>1 } && ${page.currentPageNum} &lt ${page.totalPageNum}">
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.totalPageNum}">尾页</a>&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.currentPageNum+1}">下一页</a>&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.currentPageNum-1 }">上一页</a>&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=1">首页</a>&nbsp;&nbsp;
</c:if>
<c:if test="${page.currentPageNum == page.totalPageNum }">
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=${page.currentPageNum-1 }">上一页</a>&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/mvc/toDownLoad?currentPageNum=1">首页</a>&nbsp;&nbsp;
</c:if>


当前第${page.currentPageNum }/${page.totalPageNum }页,总记录数:${page.totalCount }
</body>
页面中没有取出数据


1楼2015-02-04 12:39回复
    在Controller中是可以获取page数据的,但是传到页面中没有显示


    2楼2015-02-04 12:41
    收起回复
      2026-02-06 08:49:25
      广告
      不感兴趣
      开通SVIP免广告
      66666


      来自Android客户端3楼2015-02-04 12:46
      回复
        mybatis已经有非常成熟的分页插件了,别重复的轮子啊,不然永远活在石器时代。
        http://git.oschina.net/free/Mybatis_PageHelper


        4楼2015-02-04 14:41
        收起回复


          来自iPhone客户端5楼2015-02-04 15:50
          回复
            SpringMVC+Mybatis分页+Spring+ehcache缓存 源码下载:http://darrenzhong.com/?p=1346 你可以看看


            IP属地:辽宁6楼2015-02-06 14:15
            回复