1.引入依赖

pom.xml2

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

2.ShiroConfig编写shiroDialog

@Bean(name = "shiroDialect")
    public ShiroDialect shiroDialect(){
        return new ShiroDialect();
    }

3.在html中添加xmlns

<html lang="en" xmlns:th="http://www.thymeleaf.org"
                xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

4.在标签中使用shiro

<!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</title>
</head>
<body>
<!--从seesion中判断是否有用户-->
<div th:if="${session.loginUser==null} ">
    <a th:href="@{/toLogin}">登陆</a>
</div>
<div th:if="${session.loginUser != null}">
    <a th:href="@{/logout}">注销</a>
</div>
<div shiro:hasPermission="user-add">
    <a th:href="@{/user/add}">add</a>
</div>
<div shiro:hasPermission="user-update">
    <a th:href="@{/user/update}">update</a>
</div>
</body>
</html>

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2021-10-06
  • 2021-10-18
  • 2022-01-29
  • 2021-08-19
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2021-07-29
  • 2022-12-23
  • 2021-08-19
  • 2021-07-12
相关资源
相似解决方案