2016-12-14 12 views
0

私はデータベースからint値を呼び出して、thymeleafとSpring Bootを使って自分のHTMLに表示する星の数を決定しますが、$ {#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

まあ、私はそれをテストしたマイケル・ペッチのおかげで、それはあなた自身の質問に答えるために奇妙な知っているが、問題がシーケンスにあることがわかりました。シーケンスは、問題を解決し

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

にそれを変更する1.

のステップで作成することができませんでしたので、私はobj.starsに0の値を持っていたとき、それは1から開始したこと。

関連する問題