【发布时间】:2017-04-30 04:24:06
【问题描述】:
我正在从数据库中调用一个 int 值,以确定应该使用 thymeleaf 和 Spring Boot 在我的 html 中显示的星数,但使用 ${#numbers.sequence(1,obj.stars)} 不会好像没用。
这是我的 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;
}
【问题讨论】:
-
您遇到的错误是什么?百里香代码是正确的(刚刚测试过)。您是否验证了视图源,并确保它与您的 css 无关?
-
错误是这样的:出现意外错误(类型=内部服务器错误,状态=500)。评估 SpringEL 表达式的异常:“#numbers.sequence(1,obj.stars)”(/Obj/index)
-
obj.stars 是否解析为整数?
-
jum,也许这就是问题所在。我不知道如何让 #numbers.sequence 将 obj.stars 视为整数
-
stars 被定义为私有 int 星星;在实体中
标签: html spring spring-boot thymeleaf