0
我從數據庫中調用一個int值來確定應該在我的html中使用thymeleaf和Spring Boot顯示的恆星數量,但是使用$ {#numbers.sequence(1,obj.stars)}不會似乎工作。Thymeleaf:如何將#numbers.sequence()與變量限制一起使用?
這是我的HTML thymeleaf代碼:
<tr th:each="obj : ${allObjs}" class="pointer" th:onclick="'javascript:openobj(\'' + ${obj.id} + '\');'">
<td class="text-center" th:text="${obj.id}"></td>
<td class="text-center" th:text="${obj.code}"></td>
<td class="text-center" th:text="${obj.name}"></td>
<td class="text-center" th:text="${obj.contract}"></td>
<td class="text-center" th:text="${obj.difficulty}"></td>
<td class="text-center" th:text="${obj.priority}"></td>
<td class="text-center">
<!--this is the line I can't get to work :(-->
<span class="fa fa-star-o" th:each="star:${#numbers.sequence(1,obj.stars)}"></span>
</td>
<td class="text-center" th:text="${obj.state}"></td>
<td class="text-center" th:text="${obj.percent}"></td>
<td class="text-center" th:text="${obj.term}"></td>
<td class="text-center" th:text="${obj.version}"></td>
<td class="text-center" th:text="${obj.price}"></td>
</tr>
和我的控制器
@GetMapping("/Obj")
public ModelAndView index() {
ModelAndView view = new ModelAndView("/Obj/index");
view.addObject("title", "Obj");
List<Obj> allObjs = ObjService.findAll();
view.addObject("allObjs", allObjs);
return view;
}
你得到的錯誤是什麼?該thymeleaf代碼是正確的(只是測試它)。你有沒有驗證視圖源,並確保它不是你的CSS? – Metroids
錯誤是這樣的: 有一個意外的錯誤(type = Internal Server Error,status = 500)。 異常評估SpringEL表達式:「#numbers.sequence(1,obj.stars)」(/ Obj/index) –
確實obj.stars解析爲一個整數嗎? – Metroids