我想在Thymelaf模板中使用带有hasRole的Java类常量。
今天我使用:
<div sec:authorize="${hasRole('USR')}">
...
</div>
但是我想使用我的常量(在我的java类中声明)
public class Consts{
public static final String USR_CONST = "USER";
}
如何将字符串值('USR',hasRole参数)更改为常量USR_CONST?
您可以使用SpEl类型运算符T
来访问静态常量。例如:
<div sec:authorize="${hasRole(T(Consts).USR_CONST)}">
...
</div>
您需要在T(...)
中指定Consts
类的完全限定路径