Reputation: 523
I would like to use my Java class constants with hasRole in my Thymeleaf template.
Today I use :
<div sec:authorize="${hasRole('USR')}">
...
</div>
But I would like to use my constants (declared inside my java class)
public class Consts{
public static final String USR_CONST = "USER";
}
How can I change the string value ('USR' , hasRole parameter ) to constant USR_CONST ?
Upvotes: 0
Views: 1407
Reputation: 1279
You can use the SpEl Type Operator T
to access static constants. eg:
<div sec:authorize="${hasRole(T(Consts).USR_CONST)}">
...
</div>
You'll need to specify the fully qualified path to your Consts
class within the T(...)
Upvotes: 1