Java Thymeleaf - 评估 SpringEL 表达式的异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40987802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:03:21  来源:igfitidea点击:

Thymeleaf - Exception evaluating SpringEL expression

javaspring-bootthymeleaf

提问by user2125722

I am using #strings.substr()function and it gives the following error:

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

出现意外错误(type=Internal Server Error, status=500)。评估 SpringEL 表达式的异常:"#strings.substr(status,iter.index,iter.index+1)"(init:37)

This is the code:

这是代码:

<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>

This is the error log:

这是错误日志:

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

I guess the error is due to the fact iter.indexis of type Integerand the function expects an int. So how do I solve this issue ? Thanks

我猜这个错误是由于iter.indexInteger类型并且该函数需要一个int。那么我该如何解决这个问题呢?谢谢

采纳答案by RoToRa

No, the problem is (quoting from your error message):

不,问题是(引用您的错误消息):

Method substr [...] cannot be found on org.thymeleaf.expression.Strings type

在 org.thymeleaf.expression.Strings 类型上找不到方法 substr [...]

That means #stringsdoesn't have a method called substr. You probably mean substring.

这意味着#strings没有名为substr. 你可能是说substring

See http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#strings

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