自学springboot之整合shiro +thymeleaf

SpringBoot+Shiro+Thymeleaf+MyBatis网站后台管理系统(附源码) 内置功能 1. 用户管理:用户是系统操作者。 2. 部门管理:配置系统组织机构。 3. 岗位管理:岗位是用户所属职务。 4. 菜单管理:配置系统菜单(支持控制到按钮)。 5. 角色管理:角色菜单权限分配。 6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 7. 操作日志:系统操作日志记录(含异常)。 8. 登录日志:系统登录情况记录(含异常)。 9. 在线用户:当前系统中活跃用户状态监控。(可强退) 10. 定时任务:动态添加、修改和删除定时任务管理。 11. 代码生成: 阅读详情

springboot + Shiro + thymeleaf

什么是Shiro?

  • Apache Shiro是一个java的安全(权限)框架
  • Shiro可以非常容易开发出足够好的应用,其不仅可以用在javaSE环境,也可以用在javaEE环境
  • Shiro可以完成认证、授权、会话管理、web集成、缓存等

有哪些功能?
在这里插入图片描述
Authentication:用户认证(登录)
Authorization:权限控制
Session Management:会话管理
Cryptography:数据加密
Web Support:支持web的API
Caching:缓存
Concurrency:支持多线程应用程序
Testing:测试的支持
“Run As”:假设一个用户为另一个用户的身份
“Remember Me”:在Session中保存用户身份
在这里插入图片描述
可以看到:应用代码直接交互的对象是Subject,也就是说Shiro的对外API核心就是Subject;
其每个 API 的含义:
Subject :主体,代表了当前“用户”,这个用户不一定是一个具体的人,与当前应用交互
的任何东西都是 Subject,如网络爬虫,机器人等;即一个抽象概念;所有 Subject 都绑定
到 SecurityManager,与 Subject 的所有交互都会委托给 SecurityManager;可以把 Subject 认
为是一个门面;SecurityManager 才是实际的执行者;
SecurityManager :安全管理器;即所有与安全有关的操作都会与 SecurityManager 交互;
且它管理着所有 Subject;可以看出它是 Shiro 的核心,它负责与后边介绍的其他组件进行
交互,如果学习过 SpringMVC,你可以把它看成 DispatcherServlet 前端控制器;
Realm: :域,Shiro 从从 Realm 获取安全数据(如用户、角色、权限),就是说 SecurityManager
要验证用户身份,那么它需要从 Realm 获取相应的用户进行比较以确定用户身份是否合法;

也需要从 Realm 得到用户相应的角色/权限进行验证用户是否能进行操作;可以把 Realm 看
成 DataSource,即安全数据源。

也就是说对于我们而言,最简单的一个 Shiro 应用:
1、 应用代码通过 Subject 来进行认证和授权,而 Subject 又委托给 SecurityManager;
2、 我们需要给 Shiro 的 SecurityManager 注入 Realm,从而让 SecurityManager 能得到合法
的用户及其权限进行判断。

接下来我们来从 Shiro 内部来看下 Shiro 的架构
在这里插入图片描述

shiro整合springboot

  1. 新建项目,确保导入依赖

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.0.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.ryan</groupId>
        <artifactId>springboot-shiro</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>springboot-shiro</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>11</java.version>
        </properties>
    
        <dependencies>
            <!--shiro-spring -->
            <dependency>
                <groupId>org.apache.shiro</groupId>
                <artifactId>shiro-spring</artifactId>
                <version>1.5.3</version>
            </dependency>
            <!--数据库驱动-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.47</version>
            </dependency>
            <!--shiro整合thymeleaf-->
            <!--thymeleaf-extras-shiro -->
            <dependency>
                <groupId>com.github.theborakompanioni</groupId>
                <artifactId>thymeleaf-extras-shiro</artifactId>
                <version>2.0.0</version>
            </dependency>
    
            <!--mybatis-springboot-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.1</version>
            </dependency>
    
            <!--druid -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.22</version>
            </dependency>
    
            <!--lombok-->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    
  2. 创建数据库
    在这里插入图片描述

  3. 配置yaml/properties文件(整合mybatis)

    spring:
      datasource:
        username: root
        password: 1227
        url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
        driver-class-name: com.mysql.jdbc.Driver
        type: com.alibaba.druid.pool.DruidDataSource
    
        #Spring Boot 默认是不注入这些属性值的,需要自己绑定
        #druid 数据源专有配置
        initialSize: 5
        minIdle: 5
        maxActive: 20
        maxWait: 60000
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
    
        #配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入
        #如果允许时报错  java.lang.ClassNotFoundException: org.apache.log4j.Priority
        #则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4j
        filters: stat,wall,log4j
        maxPoolPreparedStatementPerConnectionSize: 20
        useGlobalDataSourceStat: true
        connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
    
    mybatis.type-aliases-package=com.ryan.pojo
    mybatis.mapper-locations=classpath:mapper/*.xml
    
  4. 编写实体类

    package com.ryan.pojo;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    import java.util.List;
    
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class User {
        private int id;
        private String username;
        private String password;
        private String perms;
    }
    
  5. 编写mapper接口和mapper.xml(此文件放在classpath的mapper目录下)

    package com.ryan.mapper;
    
    import com.ryan.pojo.User;
    import org.apache.ibatis.annotations.Mapper;
    import org.springframework.stereotype.Repository;
    
    @Repository
    @Mapper
    public interface UserMapper {
        User queryUserByName(String username);
    }
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.ryan.mapper.UserMapper">
        <select id="queryUserByName" resultType="user">
            select * from mybatis.user where username=#{username}
        </select>
    </mapper>
    
  6. 导入静态资源:略

  7. 编写controller并测试环境

    package com.ryan.controller;
    
    import org.apache.catalina.security.SecurityUtil;
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.authc.IncorrectCredentialsException;
    import org.apache.shiro.authc.UnknownAccountException;
    import org.apache.shiro.authc.UsernamePasswordToken;
    import org.apache.shiro.subject.Subject;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class UserController {
    
        @RequestMapping({"/","/index"})
        public String index(Model model){
            model.addAttribute("msg","hello,Shiro");
            return "index";
        }
    
        @RequestMapping("/user/add")
        public String add(){
            return "/user/add";
        }
    
        @RequestMapping("/user/update")
        public String update(){
            return "/user/update";
        }
    
        @RequestMapping("/toLogin")
        public String toLogin(){
            return "login";
        }
    
        @RequestMapping("/login")
        public String login(String username, String password,Model model){
            //获取当前用户
            Subject currentUser = SecurityUtils.getSubject();
            //封装用户的账号密码
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
            //执行登陆方法,如果用户名或者密码有误则分别抛出异常,如果正确则进入首页
            try {
                currentUser.login(token);
                model.addAttribute("msg",username);
                return "index";
            }catch (UnknownAccountException e){
                model.addAttribute("msg","用户名错误");
                return "login";
            }catch (IncorrectCredentialsException e){
                model.addAttribute("msg","密码错误");
                return "login";
            }
        }
        @RequestMapping("/unauthorized")
        @ResponseBody
        public String unauthorizedUrl(){
            return "抱歉,未经授权无法访问次网页";
        }
    }
    
  8. 编写config

    package com.ryan.config;
    
    import com.ryan.pojo.User;
    import com.ryan.service.UserService;
    import com.ryan.service.UserServiceImpl;
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.authc.*;
    import org.apache.shiro.authz.AuthorizationInfo;
    import org.apache.shiro.authz.SimpleAuthorizationInfo;
    import org.apache.shiro.realm.AuthorizingRealm;
    import org.apache.shiro.subject.PrincipalCollection;
    import org.apache.shiro.subject.Subject;
    import org.springframework.beans.factory.annotation.Autowired;
    
    import java.util.List;
    
    //自定义一个Realm,只需要继承AuthorizingRealm类并重写方法即可
    public class UserRealm extends AuthorizingRealm {
    
        @Autowired
        UserServiceImpl userService;
    
        //授权
        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
            System.out.println("执行了=>doGetAuthorizationInfo方法");
            SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
            Subject subject = SecurityUtils.getSubject();
            User currentUser = (User) subject.getPrincipal();//获取当前用户并强转
            String perms = currentUser.getPerms();//需要携带权限
            info.addStringPermission(perms);//有权限的才会房型
            return info;
        }
    
        //认证
        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    
            System.out.println("执行了=>doGetAuthenticationInfo方法");
            UsernamePasswordToken userToken = (UsernamePasswordToken) token;
            User user = userService.queryUserByName(userToken.getUsername());
            if(user == null){
                return null;//抛出异常
            }
            //密码错误,shiro来操作,这里的principal为user,这样在授权也可以获取到此用户
            return new SimpleAuthenticationInfo(user,user.getPassword(),"");
        }
    }
    
    package com.ryan.config;
    
    import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
    import org.apache.catalina.Realm;
    import org.apache.shiro.mgt.DefaultSecurityManager;
    import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
    import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    @Configuration
    public class ShiroConfig {
    
        //第三步:ShiroFilterFactoryBean
        @Bean
        public ShiroFilterFactoryBean shiroFilterFactoryBean(@Qualifier("securityManager") DefaultSecurityManager defaultSecurityManager){
            ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
            //设置安全管理器
            bean.setSecurityManager(defaultSecurityManager);
            //添加shiro的内置过滤器
            /*
                anon:无需认证就可以访问
                authc:必须认证了才能访问
                user:必须拥有 记住我 功能才能使用
                perms:拥有对某个资源的权限才能访问
                role:拥有某个角色权限才能访问
             */
    
            Map<String, String> filterMap = new LinkedHashMap<>();
            //设置授权,注意,授权要设置在认证之前,经测试如果放在认证后面会失效
            //添加了授权设置之后,应该在数据库的用户表中添加授权数据,并在UserRealm接收和判断
            filterMap.put("/user/add","perms[add]");
            filterMap.put("/user/update","perms[update]");
            //filterMap.put("/user/add","authc");
            //filterMap.put("/user/update","authc");
            //获取使用通配符
            filterMap.put("/user/*","authc");
            bean.setFilterChainDefinitionMap(filterMap);
            //设置登陆页面
            bean.setLoginUrl("/toLogin");
            //设置未授权页面
            bean.setUnauthorizedUrl("/unauthorized");
            return bean;
        }
    
        //第二步:SecurityManager
        //需要传参并绑定userRealm的bean,没有其别名的话默认就是其方法名
        @Bean(name = "securityManager")
        public DefaultWebSecurityManager getDefaultWebSecurityManager(@Qualifier("userRealm") UserRealm userRealm){
            DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
            //关联UserRealm
            securityManager.setRealm(userRealm);
            return securityManager;
        }
    
        //第一步:Realm
        @Bean
        public UserRealm userRealm(){
            //需要另外自定义一个Realm类
            return new UserRealm();
        }
    
        //shiro整合thymeleaf需要以下设置
        //添加这段代码的目的就是为了在thymeleaf中使用shiro的自定义tag。
        @Bean
        public ShiroDialect shiroDialect(){
            return new ShiroDialect();
        }
    }
    
  9. 整合shiro-thymeleaf

    <!DOCTYPE html>
    <html lang="en" 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>
    <hr>
    <p th:text="${msg}"></p>
    <hr>
    <!--未登陆-->
    <!--验证当前用户是否为“访客”,即未认证(包含未记住)的用户-->
    <div shiro:guest="">
        <a th:text="登陆" th:href="@{/toLogin}"></a>
    </div>
    <!--已登录-->
    <!-- 认证通过或已记住的用户-->
    <div shiro:user="">
        <a th:text="注销" th:href="@{/}"></a>
    </div>
    <!--是否有add权限-->
    <div shiro:hasPermission="add">
        <a th:href="@{/user/add}">add</a>
    </div>
    <!--是否有update权限-->
    <div shiro:hasPermission="update">
        <a th:href="@{/user/update}">update</a>
    </div>
    </body>
    </html>
    
  10. 测试:略

学习来源:B站up主狂神说,感觉不错,感兴趣的可以去看下

SpringBoot整合Shiro之Thymeleaf使用Shiro标签 目录`thymeleaf` 模板引擎使用 `shiro` 标签 thymeleaf 模板引擎使用 shiro 标签 我们紧接着 上一篇 文章,我们使用账号 jack 和账号 Tom 来分别登录,在上一篇文章测试中可以看到,这两个账号无论哪一个登录,首页页面都会显示 add 页面和 update 页面两个超链接,而对于这两个账号来说,一个拥有访问 add 页面的权限,一个拥有访问 update 页面的权限。那么问题来了,如何才能根据对应用户的身份角色来显示对应的页面呢?这就要使用 shiro 标签了 .. 阅读详情

相关推荐

springboot thymeleaf和shiro 整合——按钮可见性

1. 添加依赖 com.github.theborakompanioni thymeleaf-extras-shiro 1.2.1 2. 在shiro的configuration中配置 @Bean public ShiroDialect shiroDialect() { return new ShiroDialect(); }

soldier_123的博客 6818

SpringBoot+thymeleaf+shiro整合小总结

首先确保在不进行shiro整合时正常登录以及拥有权限,然后我们再开始,以下是我个人的思路。 首先,准备依赖(这里只讲关键依赖,目前我就用到了这些,够用就行,也别把相关依赖全部弄进来): <!--shiro依赖--> <dependency> <groupId>org.apache.shiro</groupId>...

GLH508的博客 541

springboot整合shiro+thymeleaf

springboot整合shiro+thymeleaf a.步骤: 1.创建prom文件,导入依赖 2.在resources文件下创建mappers包和templates包,并且创建配置文件application.yml,application.properties 3.创建启动类App 4.创建shiro整合springboot的配置类,以及shiro的realm文件 5.创建基础的MVC架构,pojo,mapper,service,controller b.项目目录 c.效果截图 1.启动spri

weixin_45577058的博客 607

springboot、thymeleaf集成shiro

001、文档内容介绍 使用 springboot 与 shiro 进行整合使用,实现强大的用户权限管理,其中涉及如何完成用户权限认证(即用户登录),用户授权,thymeleaf 页面整合 shiro 权限标签等知识点。 002、springboot 与 shiro 框架简介 1)springboot: ①由来 spring 的诞生是 Java 企业版的轻量级代替品。无需开发重量级的 EJB,spring 为企业级 Java 开发提供了一种相对简单的方法,通过依赖注入和面向切面编程,用简单的 Java 对象(

weixin_45528849的博客 680

阻抗匹配与史密斯(Smith)圆图

在找到点B和B'后,我们就能够测量A'到B和B'到D的弧长,前者就是C的归一化电纳值,后者为L的归一化电抗值。当然,表面上看新的点好像是一个不同的阻抗,实际上Z和1/Y表示的是同一个元件(这个新值在圆图上呈现为一个不同的点,而且反射系数也不相同,依次类推)。出现这种情况的原因是我们的图形本身是一个阻抗图,而新的点代表的是一个导纳。这个方程是在复平面(Γr, Γi)上、圆的参数方程(x - a)² + (y - b)² = R²,它以[r/(r + 1), 0]为圆心,半径为1/(1 + r)。

qq_55759599的博客 3963

机器视觉最全面试题总结

空洞卷积(Atrous Convolution)也叫做膨胀卷积、扩张卷积,最初的提出是为了解决图像分割在用下采样(池化、卷积)增加感受野时带来的特征图缩小,后再上采样回去时造成的精度上的损失。空洞卷积通过引入了一个扩张率的超参数,该参数定义了卷积核处理数据时各值的间距。可以在增加感受野的同时保持特征图的尺寸不变,从而代替下采样和上采样a. 是普通的卷积过程(dilation rate = 1),卷积后的感受野为3b. 是dilation rate = 2的空洞卷积,卷积后的感受野为5。

@bangbang的博客 9212

【SpringBoot】SpringBoot + Shiro + Mybatis + Thymeleaf 整合

在 SpringBoot 工程中,通过集成 Shiro 安全框架来完成对当前登录人的权限的控制。 需求如下: 一个页面 index.html 上有 ADD、UPDATE 链接,点击 ADD 链接,则跳转到 add.html 页面;UPDATE 链接同理。现在有两个用户:root、tom。root 用户只有 ADD 访问与操作权限,tom 用户则只有 UPDATE 访问与操作权限。 如下图: 页面内容如下(没有权限判断): root 用户登录: 当然,这个 ADD 链接是可以点击的,点击之后,便显示

sco5282的博客 1398

无GPS室内飞行:基于PX4与MID360的FAST-LIO定点悬停实战解析

本文详细解析了基于PX4飞控与大疆MID360激光雷达的无GPS室内飞行技术,重点介绍了FAST-LIO算法在定点悬停中的应用。通过硬件配置、软件环境搭建、坐标系转换等实战经验,帮助开发者解决室内定位难题,实现精准悬停与稳定飞行。

weixin_29056781的博客 263

shiro入门案例,springboot+shiro+thymeleaf

Shiro shiro的核心组件: 用户、角色、权限 会给角色赋予权限,给用户赋予角色 组件: 1、UsernamePasswordToken, shiro用来封装用户的登录信息,使用用户的登录信息来创建令牌TOken, 2、SecurityManager,shiro的核心,负责安全认证和授权 3、Subject,Shiro的一个抽象概念,包含了用户的信息 4、Realm,开发者自定义的模块,根据项目的需求,验证和授权的逻辑全部卸载Realm中 5、AuthenticationInfo,用户的角色信息集合,

weixin_44162147的博客 567

RK3588 ENV 环境配置之 fw_printenv

RK3588 ENV环境配置指南 本文详细介绍了在RK3588平台上配置ENV环境变量的完整流程。首先需要在parameter分区表中划分env分区,然后在U-Boot中配置MMC偏移地址。接着编译fw_printenv工具并部署到目标设备,配置fw_env.config文件指定存储位置。重点解决了内核中读写ENV时遇到的CRC校验问题,通过U-Boot的saveenv命令初始化环境变量存储区域。最后展示了如何使用fw_printenv/fw_setenv工具在内核中读写ENV变量,并建议将配置集成到根文件

501846585_QQAndroid_java 1035

springboot整合shiro(超详细,你想要的都在这了)

Springboot整合Shiro 文章目录pom依赖前端页面(thymeleaf整合shiro)thymeleaf中shiro标签解释数据库理解shiro的几个组成部分编写Shiro配置类 pom依赖 <dependencies> <!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId>

GOV_D的博客 1万+

CSP - 2024 普及组初赛试题及解析

CSP - 2024 普及组初赛试题及解析

QD_Jason的博客 2911

Shiro学习笔记_04:Shiro整合springboot之 thymeleaf权限控制

Shiro 学习笔记 本文基于B站UP主【编程不良人】视频教程【2020最新版Shiro教程,整合SpringBoot项目实战教程】进行整理记录,仅用于个人学习交流使用。 视频链接:https://www.bilibili.com/video/BV1uz4y197Zm 官方文档:http://www.baizhiedu.xin 目录标题Shiro 学习笔记七、Shiro整合springboot之thymeleaf权限控制1.引入扩展依赖2.页面中引入命名空间3.常见权限控制标签使用4.加入shiro的方

耿鬼不会笑的博客 4229

世界职业院校技能大赛商贸赛道项目参考逐字稿一

商贸赛道“智选优品”—基于大数据与AI驱动的跨境电商平台项目参考逐字稿您订阅本专栏后即可`永久享有所有文章的查阅权`,希望我们更新的参考资料能帮助到您。如果您需要我们团队赋能培训可联系我(企业一线工程师及国一获奖选手在线培训支持:每周直播精讲(可回放,支持弹幕答疑)、代码Review+技术售后(拉群随时问,12h内响应)、④路演PPT+答辩话术一对一点评,评委视角提前彩排、适合:中职/高职赛项选手、指导老师带队、校企工作室、整校打包另谈(可开发票))

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 1591

基于FPGA的64点fft变换verilog开发

这精度的损失在10bits看来对最后的误差的影响是存在是不可忽略的。此后,在这思想基础上又开发了高基和分裂基等快速算法,随着数字技术的高速发展,1976年出现建立在数论和多项式理论基础上的维诺格勒傅里叶变换算法(WFTA)和素因子傅里叶变换算法。采用这种算法能使计算机计算离散傅里叶变换所需要的乘法次数大为减少,特别是被变换的抽样点数N越多,FFT算法计算量的节省就越显著。采用这种算法能使计算机计算离散傅里叶变换所需要的乘法次数大为减少,特别是被变换的抽样点数N越多,FFT算法计算量的节省就越显著。

FPGA/MATLAB学习教程/源码/项目合作开发 1977

Springboot整合Shiro框架入门

Springboot中集成Shiro框架1、快速开始demo2、Springboot集成Shiro2.1、环境搭建2.2、shiro的拦截2.3、shiro的认证2.4、整合mybatis2.5、shiro进行授权2.6、shiro整合thymeleaf 1、快速开始demo 来到shiro的官网:shiro官方网站: 下载官方在git仓库上提供的源码,下载后解压: 官方提供了在多种场景下使用的demo,等一下会用到sample里面的东西。下面直接按官方推荐的10分钟入门demo进行测试。 创建一

qq_42640067的博客 2153

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot整合shiro整合thymeleaf详细示例

SpringBoot整合shiro+thymeleaf详细示例准备工作:1.所需的maven依赖2.搭建测试项目2.1创建后台结构和所需类2.2 创建数据库2.3 编写配置文件2.4 编写pojo,dao,service包下的类方法2.5 controller层以及前端页面3.编写核心配置类开始测试: 这是一片从头到尾的详细整合演示,让你直接复制就能运行的代码。 准备工作: 1.所需的maven依...

chengweimam的博客 1594

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

shiro+thymeleaf 整合

SpringBoot中实现Shiro控制ThymeLeaf界面按钮级权限控制 移动开发 ## 需求简述 在业绩核算系统中,我们使用了SpringBoot作为项目的整体架构,使用ThymeLeaf作为前端界面框架,使用Shiro作为我们的权限控制框架,Shiro作为轻量级的权限框架,使用起来非常方便,但是在使用的过程中我发现,Shiro作为页面级的权限控制框架非常好用,它可以注入到Con...

贱气逼人的博客 2万+

SpringBoot2.0,Thymeleaf与Shiro整合

前言 在2017年年底发布的一篇博客中介绍了前后端分离的场景下,springboot与shiro整合,时隔一年多,springboot早已升级到2.X,前后端分离也慢慢回归一体化,于是有了这样一篇博客,本文主要介绍在前后端不分离的场景下,springboot2与shiro以及thymeleaf模板引擎的整合。另外,在之前的文章中很多评论提到的问题,在本文也会一并解答。 正文 先介绍本项目中使...

Ian的博客 9061

SpringBoot与Shiro整合

本文章介绍了Spring boot下shiro与thymeleaf、mybatis的整合过程,Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理

fangliangke的博客 6521

SpringBoot自学(五)整合shiro

一、pom.xml 关于shiro使用全部依赖,因为我使用thymeleaf模块,所以才有thymeleaf+shiro的依赖,如果是其它前端模板,需要导入其它依赖 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.re...

互联网叫兽 4517

【shiro基础】springboot + shiro整合thymeleaf

springboot 快速集成 shiro ,通过自定义realm,完成基于数据库(mysql)的权限认证及鉴权,并结合thymeleaf 完成认证授权过程

一只懂代码不懂人情世故的源码爱好猿 2121

【笔记】springBoot快速 整合shiro-redis和thymeleaf

在spring boot时代的我们,要站在巨人的肩膀上快速实现springboot整合shiro-redis功能

深渊码头 3658

shiro、SpringBoot集成shiro、shiro整合mybatis、shiro整合Thymeleaf

微服务阶段笔记–3 Shiro 基本功能点 Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在 JavaSE 环境,也可以用在 JavaEE 环境。Shiro 可以帮助我们完成:认证、授权、加密、会话管理、与 Web 集成、缓存等。 Authentication:身份认证 / 登录,验证用户是不是拥有相应的身份; Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限;即判断用户是否能做事情。常见的如:验证某个用户是否拥有某个角色。或者细粒度的验证某个用户对某个资源是

m0_48896264的博客 492
上一篇: 自学springboot之整合Spring Security + thymeleaf
下一篇: 自学springboot之整合swagger
codebeef
博客等级 码龄7年 8粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值