下载了运行项目后,访问路径:http://localhost/shiro/login

[Shiro] - Shiro之SpringBoot中的使用

 这篇应该在进阶后面的.

 shiro中的重中之重,一定要看.

 基于springboot+thymeleaf+shiro做了一个demo,

在thymeleaf模板中使用shiro标签需要添加额外一个依赖:

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

而在html页面中可以这样使用:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>后端首页</title>
</head>
<body>

<div th:fragment="include/menu"></div>

<!--获取用户信息,及退出按钮-->
<shiro:user>
    欢迎<shiro:principal/>登录,<a href="/admin/doLogout">退出</a>
</shiro:user>

<!--游客访问,显示登录选项-->
<shiro:guest>
<a href="/admin/login">登录</a>
</shiro:guest>
</body>


</html>

通过<shiro:user> , <shiro:principal />来判定登录后的展示,如,欢迎,谁谁谁(用户名) <shiro:guest> 来展示未登录的用户,显示登录选项

 

相关文章:

  • 2022-02-13
  • 2022-12-23
  • 2021-07-14
  • 2021-12-23
  • 2021-11-21
  • 2021-08-16
  • 2021-09-07
  • 2021-06-02
猜你喜欢
  • 2021-04-15
  • 2021-09-03
  • 2022-02-27
  • 2021-04-30
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案