当前位置:首页 > 编程笔记 > 正文
已解决

SpringSecurity授权--前端进行访问控制

来自网友在路上 165865提问 提问时间:2023-09-23 18:31:37阅读次数: 65

最佳答案 问答题库658位专家为你答疑解惑

目录

(1)引入依赖

(2)页面


SpringSecurity可以在一些视图技术中进行控制显示效果。例如Thymeleaf中,只有登录用户拥有某些权限才会展示一些菜单

(1)引入依赖

<!--Spring Security整合Thymeleaf-->
<dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

(2)页面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head><meta charset="UTF-8"><title>主页面</title>
</head>
<body>
<h1>主页面</h1>
<ul><li sec:authorize="hasAnyAuthority('/reportform/find')"><a href="/reportform/find">查询报表</a></li><li sec:authorize="hasAnyAuthority('/salary/find')"><a href="/salary/find">查询工资</a></li><li sec:authorize="hasAnyAuthority('/staff/find')"><a href="/staff/find">查询员工</a></li>
</ul>
<a href="/logout">退出登录</a>
</body>
</html>

 

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"SpringSecurity授权--前端进行访问控制":http://eshow365.cn/6-12242-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!