spring-mvc - 如果用户具有特定角色,如何附加 CSS 类?
问题描述
th:classappend
仅当用户具有特定角色时,如何将类附加到元素?
像这样的东西:
<div th:classappend="${hasRole('EDITOR')?'glow':''}"></div>
我正在使用 Spring Boot、Spring Security 和 Thymeleaf。
解决方案
您可以使用request变量,它指向当前的HttpServletRequest:
<div th:classappend="${#request.isUserInRole('EDITOR')?'glow':''}"></div>
推荐阅读
- python-3.x - 如何使用 .to_csv() 避免在行尾出现双引号
- python - 有没有办法将每个迭代的值分别存储在新变量中的 for 循环中?
- scala - getFromDirectory 在 akka-http 路由中不起作用
- java - Camel from smb - 结合“delete=true”和按文件名过滤
- javascript - 当 ng-show 值等于 false 时的 AngularJs 动画
- javascript - 响应式 jQuery Datatables 无法获取行的详细信息
- r - R循环遍历两个向量并将结果存储在数据框中
- python - pdfminer 提取的文本包含 CID 字符
- haskell - 如何将此 let/where 函数转换为 Haskell 中的 Lambda
- java - 如何使用 ENUM 和 SWITCH,进行基于字符串的比较