如何使用Thymeleaf调用服务方法

Joh*_*ohn 7 spring thymeleaf

因为我们可以在jsp中调用service方法如下(比如检查授权):

<sec:authorize var="hasLicense" access="@licenseService.hasCapability('Event')"/>
Run Code Online (Sandbox Code Playgroud)

使用Thymeleaf时如何调用此方法?

我知道,我们可以检查角色如下,但无法得到上述案例的例子:

<li class="link" sec:authorize="hasRole('event')">
Run Code Online (Sandbox Code Playgroud)

ben*_*uly 17

Thymeleaf允许使用@beanName语法访问在Spring Application Context中注册的bean,例如:

<div th:text="${@urlService.getApplicationUrl()}">...</div>
Run Code Online (Sandbox Code Playgroud)

http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html

所以这应该工作:

<li class="link" sec:authorize="${@licenseService.hasCapability('Event')}">
Run Code Online (Sandbox Code Playgroud)