JAVA全系列 教程
3762个小节阅读:7088.6k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Shrio可以在一些视图技术中进行控制显示效果。例如Thymeleaf中,只有认证用户拥有某些权限才会展示一些菜单。
在pom中引入Shiro和Thymeleaf的整合依赖
xxxxxxxxxx
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
在配置文件中注册ShiroDialect
xxxxxxxxxx
@Bean
public ShiroDialect shiroDialect(){
return new ShiroDialect();
}
在Thymeleaf中使用Shiro标签,控制前端的显示内容
xxxxxxxxxx
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="UTF-8">
<title>主页面</title>
</head>
<body>
<h1>主页面</h1>
<ul>
<li shiro:hasPermission="/reportform/find"><a href="/reportform/find">查询报表</a></li>
<li shiro:hasPermission="/salary/find"><a href="/salary/find">查询工资</a></li>
<li shiro:hasPermission="/staff/find"><a href="/staff/find">查询员工</a></li>
</ul>
<h2><a href="/user/logout">退出登录</a></h2>
</body>
</html>
实时效果反馈
1. Shiro整合Thymeleaf,在网页标签中添加属性表示特定权限才能看到该内容
A th:hasPermission
B sec:hasPermission
C shiro:hasPermission
D shiro:hasRole
答案
1=>C