[英]How can I use the variables that added by Model.addAttribute() to pass as a parameter in hasRole method of thymeleaf?
How can I use the variables that added by Model.addAttribute() to pass as a parameter in hasRole method of thymeleaf?如何使用 Model.addAttribute() 添加的变量作为参数传递给 thymeleaf 的 hasRole 方法?
I try to do like this but it's not working:我尝试这样做,但它不起作用:
In the controller:在控制器中:
String role_Admin = userTags.role.ADMIN.name();
model.addAttribute("role_Admin", role_Admin);
and in the html file where I check authorize to show a message:并在我检查授权以显示消息的 html 文件中:
<span sec:authorize="${hasRole(${role_Admin})}">admin</span>
and it throws exception:它抛出异常:
org.thymeleaf.exceptions.TemplateProcessingException: An error happened trying to parse Spring Security access expression "hasRole(${role_Admin})"
org.thymeleaf.exceptions.TemplateProcessingException:尝试解析 Spring Security 访问表达式“hasRole(${role_Admin})”时发生错误
I used:我用了:
how can I solve it?我该如何解决?
用双下划线包裹 ${role_Admin}。
__${role_Admin}__
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.