代码之家  ›  专栏  ›  技术社区  ›  Mahozad

如果用户具有特定角色,如何附加css类?

  •  0
  • Mahozad  · 技术社区  · 6 年前

    如何将类附加到具有 th:classappend 仅当用户具有特定角色时?

    像这样的:

    <div th:classappend="${hasRole('EDITOR')?'glow':''}"></div>
    

    我用的是弹簧靴,弹簧安全和百里香。

    2 回复  |  直到 6 年前
        1
  •  1
  •   holmis83    6 年前

    你可以使用 请求 变量,它指向当前 HttpServletRequest :

    <div th:classappend="${#request.isUserInRole('EDITOR')?'glow':''}"></div>
    
        2
  •  0
  •   Mahozad    6 年前

    我找到了解决办法 Thymeleaf "extras" Spring Security github page :

    <div th:classappend="${#authorization.expression('hasRole(''EDITOR'')')?'glow':''}"></div>