gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:10:31 24 4
gpt4 key购买 nike

如何从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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com