1.pom.xml文件导入核心jar包
<!--thymeleaf和shiro整合包-->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
<!--thymeleaf转换HTML网页格式包 加完之后能够识别thymeleaf以外的扩展标签-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
2.在你的ShiroConfig配置类重写一个方法使shiro标签与thymeleaf标签结合。
// shiro标签与thymeleaf标签结合
@Bean
public ShiroDialect shiroDialect() {
return new ShiroDialect();
}
3.application.properties配置类加上支持的网页格式
#支持网页格式为HTML5
spring.thymeleaf.mode=LEGACYHTML5
4.前台引入Shiro标签库
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
如果shiro:hasPermission的权限字可以和后台的数据库查出来的关键字对应,则必须给用户赋权限,才可以访问此方法,否则页面看不到此标签,标签消失,无法访问
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<font color="red" >进入登录成功页面</font>
<a href="/logout">注销</a>
<button value="查询订单" shiro:hasPermission="book:query"></button>
<button value="查询所有订单" shiro:hasPermission="book:queryAll"></button>
<button value="查询所有订单" shiro:hasPermission="book:update"></button>
</body>
</html>