java - 从 Thymeleaf 访问常量(没有 spring)

标签 java thymeleaf

如何从Thymeleaf访问常量?

public final static int SOME_CONSTANT = 255;

我正在使用以下代码:

@com.company.project.classWithConstants@SOME_CONSTANT

我收到以下异常:

com/company/project/classWithConstants (wrong name: com/company/project/ClassWithConstants)

(SO有一个类似的问题,但OP正在使用spring:Access from Thymeleaf to class field)

最佳答案

如您所知,Thymeleaf 使用 OGNL 来处理命令。 因此,如果没有 Spring 和 SpEL,可以这样实现:

<td>
    <input class="form-control" type="text" name="inputValue"
        th:maxlength="${@com.example.yourpackagename.Constants@MAX_TESTCASE_VALUE_LENGTH}" />
</td>

OGNL documentation

关于java - 从 Thymeleaf 访问常量(没有 spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57690461/

相关文章:

spring-boot - Thymeleaf 编码问题

java - 以 thymeleaf 形式传播对象

Java 游戏对象设计

java - 使用外部数组进行插入排序?

Java 将文本文件读取到流中并将其拆分

java - 如何计算工时、费率、工资,当我编译时,我收到操作标志错误。请让我知道如何计算它们

java - 如何仅显示 thymeleaf 中不为空的变量

c# - 有没有从 Java netbeans 项目调用 .net 类的好方法?

java - URL 中的 Thymeleaf 2 表达式

java - 如何使用 th :classapend if a form error on another field exists?