我正在使用 #strings.substr()
函数,它给出了以下错误:
There was an unexpected error
(type=Internal Server Error, status=500)
. Exception evaluating SpringEL expression:"#strings.substr(status,iter.index,iter.index+1)"
(init:37)
这是代码:
<tbody>
<tr th:each="task,iter : ${taskList}">
<td th:text="${task.id}"></td>
<td th:text="${task.task}"></td>
<td th:switch="${#strings.substr(status,iter.index,iter.index+1)}">
<div th:case="'0'"><input type="checkbox"/></div>
<div th:case="'1'"><input type="checkbox" checked="checked"/></div>
<div th:case="*"><input type="checkbox" id="checkbtn" checked="checked"/></div>
</td>
</tr>
</tbody>
这是错误日志:
Exception evaluating SpringEL expression: "#strings.substr(status,iter.index,iter.index+1)" (init:37)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 9): Method call: Method substr(netgloo.models.Exit,java.lang.Integer,java.lang.Integer) cannot be found on org.thymeleaf.expression.Strings type
我猜这个错误是由于 iter.index 的类型是 Integer 并且该函数需要一个 int。那么我该如何解决这个问题呢?谢谢
最佳答案
不,问题是(引用您的错误消息):
Method substr [...] cannot be found on org.thymeleaf.expression.Strings type
这意味着 #strings
没有名为 substr
的方法。您可能是指 substring
。
参见 http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#strings
关于java - Thymeleaf - 异常评估 SpringEL 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40987802/