luckyxl0 2020-05-05
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>