shiro整合thymeleaf

1、引入依赖

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

2、ShiroConfig中编写shiroDialect

  @Bean(name = "shiroDialect")
    public ShiroDialect shiroDialect(){
        return new ShiroDialect();
    }

3、html页面添加xmlns

<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

4、在标签中使用shiro标签

<div shiro:hasPermission="add">
    <a href="/1">1111</a>
</div>

<div shiro:hasPermission="update">
    <a href="/2">2222</a>
</div>

<div shiro:hasPermission="all">
    <a href="/1">1111</a>
    <a href="/2">2222</a>
</div>

 注:根据不同权限某些功能进行隐藏和展示:

如:admin账号具有最大权限,则可以看到所有功能

  zhangsan具有修改权限,则只能看到修改按钮

  lisi具有增加权限,则只能看到增加按钮

原文地址:https://www.cnblogs.com/wangzh1guo/p/10158433.html