Thymeleaf - 评估SpringEL表达式的异常

时间:2016-12-06 04:23:53

标签: java spring-boot thymeleaf

我正在使用#strings.substr()函数,它会出现以下错误:

  

出现意外错误(type=Internal Server Error, status=500)。   评估SpringEL表达式的异常:"#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 属于整数,而且函数需要 int 。那么我该如何解决这个问题呢?感谢

1 个答案:

答案 0 :(得分:1)

不,问题是(引用错误信息):

  

在org.thymeleaf.expression.Strings类型

上找不到方法substr [...]

这意味着// use intent to send broadcast Intent i = new Intent("com.myapp.DOWNLOADCOMPLETE"); sendBroadcast(i); 没有名为#strings的方法。你的意思可能是substr

请参阅http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#strings

相关问题