1.页面环境是基于jsp的
需要在你需要的页面导入标签库:
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
2.上代码
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
状态码:${result.code}
<form action="/login" method="post">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="submit" value="登陆">
</form>
<br/>
//只有没登录的时候才能看见
<shiro:guest>
登陆
</shiro:guest>
<br/>
//登录后才能看见
<shiro:authenticated>
当前用户为:<shiro:principal property="username"/>
<a href="/logout">退出</a>
</shiro:authenticated>
<br/>
//只有拥有什么样的角色才能查看
<shiro:hasRole name="admin">
这个是具有admin角色的用户才能看的见
</shiro:hasRole>
<br/>
//拥有什么样的权限才能查看
<shiro:hasPermission name="user:get">
这个是具有user:get的权限的用户才能看的见
</shiro:hasPermission>
</body>
</html>
3.先添加thymeleaf+shiro的依赖
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
4.页面加入
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
5.这就和jsp一样支持shiro了