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;
}
エラーは何ですか?そのthymeleafコードは正しい(ちょうどそれをテストした)。ビューソースを確認して、あなたのCSSで何かではないことを確認しましたか? – Metroids
エラーは次のとおりです。 予期しないエラーが発生しました(type = Internal Server Error、status = 500)。 SpringEL式を評価している例外: "#numbers.sequence(1、obj.stars)"(/ Obj/index) –
obj.starsは整数に解決されますか? – Metroids