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