在我的 spring 控制器中,我有 while 回圈每次都會獲取新值,我想從模型屬性向 JSP 發送新值,這用于折線圖
uj5u.com熱心網友回復:
參考您的評論:I have while loop which extract text from many images ,this while loop in inside separate thread , I'm only getting the last value after while loop finishes ,model.attribute("send",newvalues) is inside while loop .
這意味著您的值將立即被回圈內的新值替換,因為它們具有相同的變數名稱。因此,您要么需要將它們存盤在不同的變數中,要么按照以下步驟操作:
- 在回圈外宣告一個串列
- 現在,在回圈內,將值添加到串列中
- 回圈外,回傳jstl頁面
這應該有效。如果您在執行此操作時遇到任何困難,請告訴我。
uj5u.com熱心網友回復:
我希望這會幫助你實作你的目標。
通過添加以下 taglib 指令在 JSP 頁面中使用 JSTL 核心標簽:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
為了迭代串列值,JSTL 核心有 <c:forEach/> 標簽。它將一一顯示串列值。
<c:forEach var="emp" items="${empList}">
...
</c:forEach>
需要依賴
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
參考:https : //www.websparrow.org/spring/how-to-iterate-list-on-jsp-in-spring-mvc
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/377768.html
