一.在普通的Jsp中使用Shiro标签
1.引入头文件
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
2.Shiro标签
![这里写图片描述](https://img-blog.csdn.net/20170921155711614?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHI3ODc3NTM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
二.在Thymeleaf中使用Shiro标签
1.Pom中加入:
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>1.0.2</version> //本人亲测 2.0以上报错
</dependency>
2.在配置类中加入此Bean
@Bean
public ShiroDialect shiroDialect() {
return new ShiroDialect();
}
3.在HTML标签中添加:
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
即:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
4.使用shiro标签
![这里写图片描述](https://img-blog.csdn.net/20170921160659043?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHI3ODc3NTM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
—–End Shiro标签的详解
1.guest标签
游客标签,未登录才能看到的东西
2.user标签
用户标签 ,用户通过验证或者是记住我进来的才能看到。
3.authenticated标签
验证的标签 即用户通过login方法进来的,不是通过记住我进来的
4.notAuthenticated标签
即没有调用Subject.login进行登录,包括记住我自动登录的也属于未进行身份验证
5.shiro: principal
用户的信息shiro:principal property=”username” 相当于((User)Subject.getPrincipals()).getUsername()。
6.hasRole标签 hasPermission标签
有这些权限 有这些角色才能看到的。
7.lacksPermission标签 lacksRole标签
没有这些权限 角色才能看到的。
8.hasAnyRoles标签 name=”role1,role2….”
当前Subject有任意一个角色(或的关系)将显示body体内容。 有role1或者role2都能看见