您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用Thymeleaf配置SpringBoot并使用sec:authentication标记

如何使用Thymeleaf配置SpringBoot并使用sec:authentication标记

您需要在项目中添加Spring Security 3集成模块。这些模块是Thymeleaf的方言,等同于Spring安全标签lib。这些是百里香额外的模块,不是百里香核心的一部分。

在您的模板引擎中,只需添加集成模块方言即可。

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
 ...
  <property name="additionalDialects">
    <set>
      <bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>
    </set>
  </property>
  ...
</bean>

添加模块后,可以使用以下代码

<div sec:authentication="name">The value of the "name" property of
    the authentication object should appear here.</div>

Thymeleaf等效模块可在此处找到。另外,请参考他们的这个逐步教程

更新:

如果您使用的是Spring Boot,则只需在pom.xml中添加依赖项或在项目中添加jar。

Java 2022/1/1 18:15:18 有601人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶