java 从 Thymeleaf 访问类字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25120799/
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-11-02 07:23:36 来源:igfitidea点击:
Access from Thymeleaf to class field
提问by Cichy
How to access from Thymeleaf to some simple POJO static property ? For example:
如何从 Thymeleaf 访问一些简单的 POJO 静态属性?例如:
public final static int PROJECT_NAME_MAX_LENGTH = 255;
how to type:
如何输入:
<input type="text" th:maxlength="??" />
回答by Sotirios Delimanolis
Since you are using Spring, thymeleaf has access to the EL provided by Spring. You should therefore be able to use
由于您使用的是 Spring,因此 thymeleaf 可以访问 Spring 提供的 EL。因此,您应该能够使用
<input type="text" th:maxlength="${T(com.example.MyType).PROJECT_NAME_MAX_LENGTH}" />