0
点赞
收藏
分享

微信扫一扫

shiro与security前端显示当前用户的数据

王远洋 2022-03-30 阅读 45
java后端

无论是在使用shiro还是security都需要导入相关的依赖,就是thymeleaf整合这两个包的相关依赖和命名空间

xmlns:th="http://www.thymeleaf.org <!--thymeleaf的命名空间-->
xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity5” <!--security的命名空间-->
xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro"  <!--shiro的命名空间-->

shiro在前段显示用户名

依赖

<!--thymeleaf-shiro-->
<dependency>
    <groupId>com.github.theborakompanioni</groupId>
    <artifactId>thymeleaf-extras-shiro</artifactId>
    <version>2.1.0</version>
</dependency>

首先要在认证的时候把user对象传递出去。
在这里插入图片描述然后在前前端我们可以通过如下的代码来显示出我们想要的数据
其中property=“name” 中的name,对应的就是实类中的属性,如果不加property那么前端将显示这个用户的全部信息

<span shiro:principal property="name"/>

security在前端显示用户名

依赖

<!--thymeleaf整合security-->
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

通过下边的代码就可以了

<span sec:authentication="name"></span>
举报

相关推荐

0 条评论