【问题标题】:Avoid to get user informations inside every method/controller Spring Boot避免在每个方法/控制器 Spring Boot 中获取用户信息
【发布时间】:2018-05-20 08:33:14
【问题描述】:

我正在使用Spring Boot,我想在我的navbar 中显示登录用户的姓名。

为此,我必须在每个控制器的每个方法中调用主体,然后将信息添加到模型中。 我认为有更好的方法来做到这一点。我想到了session attribute。对吗?

所以我的问题是:会话属性是最佳选择吗? 如果是,我该怎么做?

【问题讨论】:

标签: spring authentication spring-boot session-variables principal


【解决方案1】:

你可以直接在你的jsp中使用这些东西: <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> <security:authorize access="isAuthenticated()"> authenticated as <security:authentication property="principal.username" /> </security:authorize> 取自baeldung

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 2019-04-30
    • 2016-06-02
    • 1970-01-01
    相关资源
    最近更新 更多