昨天我已经发布了这篇文章..但没有人回答它.. 我正在使用spring mvc框架。
所以我做了: -
@RequestMapping(value = "/detailssection/id",method=RequestMethod.GET)
public @ResponseBody String showthedetails(Map<String, Object> map, HttpServletRequest request) throws IOException{
//I want to display 5 details per page
int recordsPerPage = 5;
//It will count total no of records(like 300 records are there)
int totalnoOfrecords = viewService.TotalnoOfRecoredsbanglains1();
//If the totalnoOfrecords=300 then page noumber will be 300/5=60 that means 1,2....60
int pagenumbers = (int) Math.ceil(totalnoofrecords * 1.0 / recordsPerPage);
map.put("detail", new Detail());
map.put("noOfPages", pagenumbers);
map.put("detailList", viewService.viewDetails());
return "detailssection";
}
我的jsp页面如下: -
<div id= "part1">
<div id= "details">
<p>${detail.description}</p>
</div>
</c:forEach>
<%--For displaying Previous link except for the 1st page --%>
<c:if test="${currentPage != 1}">
<a href="/detailssection/id?pagenumber=${currentPage - 1}">Previous</a>
</c:if>
<%--For displaying Page numbers.
The when condition does not display a link for the current page--%>
<c:forEach begin="1" end="${noOfPages}" var="i">
<c:choose>
<c:when test="${currentPage eq i}">
${i}
</c:when>
<c:otherwise>
<a href="/detailssection/id?pagenumber=${i}">${i}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<%--For displaying Next link --%>
<c:if test="${currentPage lt noOfPages}">
<a href="/detailssection/id?pagenumber=${currentPage + 1}">Next</a>
</c:if>
</div>
但我没有得到任何页码。只显示&#34;上一页&#34; section.Its喜欢: -
我做错了什么?jsp页面有问题吗?
答案 0 :(得分:1)
让我们从开始就开始吧。
如果您的requestScope
上有地图,请假设MyMap
使用以下密钥:details
,noOfPages
和detailList
来访问它#39;按键的值,语法如下:
<c:forEach begin="1" end="$MyMap['noOfPages']" var="i" varStatus="loop">
<c:choose>
<c:when test="${currentPage eq i}">
${i}
</c:when>
<c:otherwise>
<a href="/detailssection/id?pagenumber=${loop.index}">${loop.index}</a>
</c:otherwise>
</c:choose>
</c:forEach>