上一章讲环境搭建

springboot与shiro和mybatis和mysql

 

现在讲html中怎么使用shiro标签,这里是基于上一章讲的

在pom文件引入依赖

<dependency>
    <groupId>com.github.theborakompanioni</groupId>
    <artifactId>thymeleaf-extras-shiro</artifactId>
    <version>2.0.0</version>
</dependency>

 

shiro的配置类ShiroConfig.java添加bean【at.pollux.thymeleaf.shiro.dialect.ShiroDialect】

1 @Bean
2 public ShiroDialect shiroDialect() {
3     return new ShiroDialect();
4 }

 1 <!DOCTYPE html>
 2 <html lang="en" xmlns:th="http://www.thymeleaf.org"
 3       xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
 4 
 5 <head>
 6     <title>首页</title>
 7 </head>
 8 <body>
 9 <h1>首页</h1>
10 <hr>
11 <ul>
12     <li><a href="user/index">个人中心</a></li>
13     <li><a href="vip/index">会员中心</a></li>
14     <p shiro:hasPermission="svip"><li>这是svip能看到的p标签</li></p>
15     <shiro:hasPermission name="svip"><li>这是svip能看到的</li></shiro:hasPermission>
16     <li><a href="logout">退出登录</a></li>
17 </ul>
18 </body>
19 </html>

 

接着上一章的测试

 

参考文章:https://blog.csdn.net/fox9916/article/details/80221894