gpt4 book ai didi

java - Spring mvc分页如何获取结果

转载 作者:行者123 更新时间:2023-12-01 11:08:51 27 4
gpt4 key购买 nike

我昨天已经发了这个帖子..但是没有人回复..我正在使用 spring mvc 框架。

我想做如下图所示的分页:-- enter image description here

所以我已经做到了:--

    @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>

但是我没有得到任何页码。它只显示“上一页”部分。它就像:-- enter image description here我做错了什么?jsp页面有什么问题吗?

最佳答案

让我们从头开始。

如果您的 requestScope 上有 map ,假设它是带有以下键的 MyMap:detailsnoOfPages code> 和 detailList,要通过键访问其值,语法如下:

<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>

关于java - Spring mvc分页如何获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32601142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com