shiro整合thymeleaf


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM