162. Spring Boot 在thymeleaf使用shiro标签

 

【视频 & 交流平台】

à SpringBoot视频

http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à SpringCloud视频

http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à Spring Boot源码

https://gitee.com/happyangellxq520/spring-boot

à Spring Boot交流平台

http://412887952-qq-com.iteye.com/blog/2321532

 

 

【视频&交流平台】

à Spring Boot实战篇之Shiro进入领取双十一优惠券

http://study.163.com/course/introduction.htm?courseId=1004523002

 

需求缘起:

shirojsp配合使用的时候,有针对jspshiro标签,当我们使用的是thymeleaf也是可以使用shiro标签的,这就是本节要解决的问题。

本节大纲:

(1)添加依赖
(2)在ShiroConfiguration添加配置
(3)在index方法中存放userInfo
(4)调整index.html

 

       接下来看下具体的内容:

1)添加依赖

<dependency>
           <groupId>com.github.theborakompanioni</groupId>
           <artifactId>thymeleaf-extras-shiro</artifactId>
           <version>1.0.2</version>
</dependency>

 

 

2)在ShiroConfiguration添加配置

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

 

 

3)在index方法中存放userInfo对象

       修改HomeControllerindex方法:

    @RequestMapping(value={"/","/index"})
    public String index(Map<String,Object> map){
       System.out.println("HomeController.index()");
       //获取到用户信息;
       Subject subject  = SecurityUtils.getSubject();
       UserInfo ui = (UserInfo) subject.getPrincipal();
       map.put("userInfo",ui);
       return "/index";
    }

 

 

4)调整index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
</head>
<body>
   
    <h3>主界面--<span th:text="'登录账号:'+${userInfo.username}+'--名称:'+${userInfo.name}">user</span></h3>
    <a href="/logout">退出</a>
    <hr />
   
   
    <!-- 这些实际从数据库中进行查询,可以在 -->
    <h5>这是通过shiro标签的方式;</h5>
    <p shiro:hasRole="admin">
           <a>管理员角色</a>
    </p>
   
    <p shiro:hasPermission="userInfo:query">
           <a href="/userInfo/userList">用户查询</a>
    </p>
    <p shiro:hasPermission="userInfo:add">
           <a href="/userInfo/userAdd">用户添加</a>
    </p>
 
 
       <hr />
    <h5>从数据库加载菜单</h5>
    <div th:each="roleList:${userInfo.roleList}">
       <span th:text="${roleList.description}"></span>
       <!-- 角色下所有的所有菜单,实际开发中,只需要获取所有的权限就可以了,无所谓是哪个角色的; -->
       <p style="color:blue;margin-left:30px;" th:each="permission:${roleList.permissions}">
           <a th:href="${permission.url}" th:text="${permission.name}"></a>
       </p>
    </div> 
 
</body>
</html>

 

 

 

 

======================================

Spring Boot Shiro视频实战篇【已更新】

======================================

适合人群

有Spring Boot基础的人群。

 

使用技术

(1)spring boot(整合框架)

(2)spring mvc

(3)spring data jpa(持久化操作)

(4)shiro(安全框架)

(5)thymeleaf(模板引擎)

(6)ehcache(缓存管理)

(7)mysql(数据库)

(8)js/css/img(静态资源使用)

9kaptcha(验证码库)

课程目录

1. Spring Boot Shiro介绍

 

2. Spring Boot 搭建无Shiro的框架

 

3. Spring Boot Shiro拦截

 

4. Spring Boot Shiro身份认证准备工作

 

5. Spring Boot Shiro身份认证

 

6. Spring Boot Shiro权限控制

 

7. Spring Boot Shiro缓存

 

8. Spring Boot Shiro记住密码

 

9. Spring Boot Shiro登录成功之后下载favicon.ico

 

10. Spring Boot 在thymeleaf使用shiro标签

 

11. Spring Boot Shiro密码加密算法

 

12.Spring Boot Shiro使用JS-CSS-IMG

 

13. Spring Boot Shiro限制登录尝试次数

 

14.Spring Boot Shiro 验证码

 

【视频&交流平台】

à Spring Boot实战篇之Shiro进入领取双十一优惠券

http://study.163.com/course/introduction.htm?courseId=1004523002

 

à Spring Boot交流平台

http://412887952-qq-com.iteye.com/blog/2321532

猜你喜欢

转载自412887952-qq-com.iteye.com/blog/2397397