java - Thymeleaf - 异常评估 SpringEL 表达式

标签 java spring-boot thymeleaf

我正在使用 #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/

相关文章:

java - com.fasterxml.jackson.databind.exc.InvalidDefinitionException

spring - thymeleaf : How to edit a field?

java - java中的抽象类

java - 使用 ObjectMapper 的 org.codehaus.jackson.map.JsonMappingException

java - Criteria API 中有类似 Restrictions.eq(true, false) 的东西吗?

java - 如果 JUnit 测试在没有 @RunWith 注释的情况下也能按预期工作,为什么还要向我的 JUnit 测试添加 @RunWith 注释呢?

java - 线程 "main"java.lang.AbstractMethodError 中的异常 - Spring Boot 应用程序

java - Selenium Grid TestCase 分发问题

java - 单击视频的缩略图并播放视频

Spring、Thymeleaf 和字符串列表