2016-12-14 238 views
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; 
} 
+1

你得到的錯誤是什麼?該thymeleaf代碼是正確的(只是測試它)。你有沒有驗證視圖源,並確保它不是你的CSS? – Metroids

+0

錯誤是這樣的: 有一個意外的錯誤(type = Internal Server Error,status = 500)。 異常評估SpringEL表達式:「#numbers.sequence(1,obj.stars)」(/ Obj/index) –

+0

確實obj.stars解析爲一個整數嗎? – Metroids

回答

3

嗯,我知道它的怪異回答你自己的問題,但是,由於邁克爾·佩奇誰測試它,我發現問題出在順序上。它是從1開始的時候我在obj.stars的0值,因此該序列不能與1

改變它的工序被創建以

<span class="fa fa-star-o" th:each="star:${#numbers.sequence(0,obj.stars)}"></span> 

問題解決了。

相關問題