【发布时间】:2021-08-06 18:58:04
【问题描述】:
我在 Constants 这样的类中定义了两个静态变量
public static String MIN_VALUE = 1;
public static String MAX_VALUE = 10;
我想创建一个 html 选择标签,其中包含从 MIN_VALUE 到 MAX_VALUE 的所有数字的选项。如果我在百里香中使用硬编码数字,我可以轻松做到这一点:
<select>
<option th:each="number: ${#numbers.sequence(1, 10)}" th:value="${number}" th:text="${number}"/>
</select>
但如果我尝试这样的事情:
<option th:each="number: ${#numbers.sequence(${Constants.MIN_VALUES}, ${Constants.MAX_VALUES})}" th:value="${number}" th:text="${number}"/>
我收到此错误:
EL1043E: Unexpected token. Expected 'rparen())' but was 'lcurly({)'
如何在 thymeleaf 的 numbers.sequence 方法中使用我的 Constant 类中的变量?
我发现this 问题的标题几乎相似,但我没有通过model 属性在这里传递我的变量限制。我可以使用来自 thymeleaf 标签的 Constants.VAR_NAME 从 Constants 类访问我的变量。
【问题讨论】:
-
你需要
T(com.example.Constants).MIN_VALUE。