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>
相关推荐
visionzheng 2020-04-20
丽丽 2020-10-30
86384798 2020-04-07
85291545 2020-03-26
东哥笔记 2020-02-29
goodyatou 2020-01-29
GechangLiu 2020-01-26
ffujbcf 2019-12-05
空间数据库是 2019-11-18
yangjinpingc 2018-05-20
MicroBoy 2017-03-30
努力的zhiyi 2017-01-17
姜依涛 2019-06-27
jackuseradmin 2019-06-27
newstudent0 2019-06-27
LeeEmmmm 2019-06-21
wangjie 2018-09-25
hanyueqi 2017-06-14
稀土 2018-05-11