当前位置: 首页 > news >正文

SpringBoot08:Shiro

什么是Shiro?

一个Java的安全(权限)框架,可以完成认证、授权、加密、会话管理、Web集成、缓存等

下载地址:Apache Shiro | Simple. Java. Security.

快速启动

先在官网找到入门案例:shiro/samples/quickstart at main · apache/shiro · GitHub

步骤:

1、新建一个 Maven 工程,删除其 src 目录,将其作为父工程

2、在父工程中新建一个 Maven 模块

3、在maven模块中,复制依赖

    <dependencies><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-core</artifactId><version>1.4.2</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>jcl-over-slf4j</artifactId><version>1.7.24</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.21</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies>

4、复制 log4j.properties

log4j.rootLogger=INFO, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n# General Apache libraries
log4j.logger.org.apache=WARN# Spring
log4j.logger.org.springframework=WARN# Default Shiro logging
log4j.logger.org.apache.shiro=INFO# Disable verbose logging
log4j.logger.org.apache.shiro.util.ThreadContext=WARN
log4j.logger.org.apache.shiro.cache.ehcache.EhCache=WARN

5、复制 shiro.ini(要先在 IDEA中添加 ini 插件)

[users]
# user 'root' with password 'secret' and the 'admin' role
root = secret, admin
# user 'guest' with the password 'guest' and the 'guest' role
guest = guest, guest
# user 'presidentskroob' with password '12345' ("That's the same combination on
# my luggage!!!" ;)), and role 'president'
presidentskroob = 12345, president
# user 'darkhelmet' with password 'ludicrousspeed' and roles 'darklord' and 'schwartz'
darkhelmet = ludicrousspeed, darklord, schwartz
# user 'lonestarr' with password 'vespa' and roles 'goodguy' and 'schwartz'
lonestarr = vespa, goodguy, schwartz# -----------------------------------------------------------------------------
# Roles with assigned permissions
#
# Each line conforms to the format defined in the
# org.apache.shiro.realm.text.TextConfigurationRealm#setRoleDefinitions JavaDoc
# -----------------------------------------------------------------------------
[roles]
# 'admin' role has all permissions, indicated by the wildcard '*'
admin = *
# The 'schwartz' role can do anything (*) with any lightsaber:
schwartz = lightsaber:*
# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with
# license plate 'eagle5' (instance specific id)
goodguy = winnebago:drive:eagle5

6、复制 Quickstart

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;/*** @ClassName Quickstart* @Description TODO* @Author GuoSheng* @Date 2021/4/20  17:28* @Version 1.0**/
public class Quickstart {private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class);public static void main(String[] args) {// The easiest way to create a Shiro SecurityManager with configured// realms, users, roles and permissions is to use the simple INI config.// We'll do that by using a factory that can ingest a .ini file and// return a SecurityManager instance:// Use the shiro.ini file at the root of the classpath// (file: and url: prefixes load from files and urls respectively):DefaultSecurityManager defaultSecurityManager=new DefaultSecurityManager();IniRealm iniRealm=new IniRealm("classpath:shiro.ini");defaultSecurityManager.setRealm(iniRealm);// for this simple example quickstart, make the SecurityManager// accessible as a JVM singleton.  Most applications wouldn't do this// and instead rely on their container configuration or web.xml for// webapps.  That is outside the scope of this simple quickstart, so// we'll just do the bare minimum so you can continue to get a feel// for things.SecurityUtils.setSecurityManager(defaultSecurityManager);// Now that a simple Shiro environment is set up, let's see what you can do:// get the currently executing user:Subject currentUser = SecurityUtils.getSubject();// Do some stuff with a Session (no need for a web or EJB container!!!)Session session = currentUser.getSession();session.setAttribute("someKey", "aValue");String value = (String) session.getAttribute("someKey");if (value.equals("aValue")) {log.info("Retrieved the correct value! [" + value + "]");}// let's login the current user so we can check against roles and permissions:if (!currentUser.isAuthenticated()) {UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");token.setRememberMe(true);try {currentUser.login(token);} catch (UnknownAccountException uae) {log.info("There is no user with username of " + token.getPrincipal());} catch (IncorrectCredentialsException ice) {log.info("Password for account " + token.getPrincipal() + " was incorrect!");} catch (LockedAccountException lae) {log.info("The account for username " + token.getPrincipal() + " is locked.  " +"Please contact your administrator to unlock it.");}// ... catch more exceptions here (maybe custom ones specific to your application?catch (AuthenticationException ae) {//unexpected condition?  error?}}//say who they are://print their identifying principal (in this case, a username):log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");//test a role:if (currentUser.hasRole("schwartz")) {log.info("May the Schwartz be with you!");} else {log.info("Hello, mere mortal.");}//test a typed permission (not instance-level)if (currentUser.isPermitted("lightsaber:wield")) {log.info("You may use a lightsaber ring.  Use it wisely.");} else {log.info("Sorry, lightsaber rings are for schwartz masters only.");}//a (very powerful) Instance Level permission:if (currentUser.isPermitted("winnebago:drive:eagle5")) {log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  " +"Here are the keys - have fun!");} else {log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");}//all done - log out!currentUser.logout();System.exit(0);}
}

7、运行结果

Shiro的Subject分析

Quickstart 中的一些方法:

1、获取当前用户

Subject currentUser = SecurityUtils.getSubject();

2、通过当前用户拿到 Session

Session session = currentUser.getSession();

3、用session存值取值

        session.setAttribute("someKey", "aValue");String value = (String) session.getAttribute("someKey");

4、判断是否被认证

currentUser.isAuthenticated()

5、执行登录操作

currentUser.login(token);

6、打印其标识主体

 currentUser.getPrincipal()

7、判断当前用户是否有某个角色

currentUser.hasRole("schwartz")

8、注销

 currentUser.logout();

SpringBoot整合Shiro环境搭建

步骤:

1、导入shiro的整合依赖

        <!--shiro整合spring--><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-spring</artifactId><version>1.4.1</version></dependency>

2、在config包下,编写Shiro的配置类

①自定义 Realm 类

public class UserRealm extends AuthorizingRealm {//授权@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {System.out.println("执行了shiro的授权方法");return null;}//认证@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {System.out.println("执行了shiro的认证方法");return null;}
}

②自定义 ShiroConfig


public class ShiroConfig {//ShiroFilterFactoryBean@Beanpublic ShiroFilterFactoryBean getShiroFilterFactoryBean(@Autowired DefaultWebSecurityManager defaultWebSecurityManager){ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();//设置安全管理器bean.setSecurityManager(defaultWebSecurityManager);return bean;}//DefaultWebSecurityManager@Beanpublic DefaultWebSecurityManager getDefaultWebSecurityManager(@Autowired UserRealm userRealm){DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();//关联 UserRealmsecurityManager.setRealm(userRealm);return securityManager;}//创建Realm对象,需要自定义类@Beanpublic UserRealm userRealm(){return new UserRealm();}
}

Shiro实现登录拦截

功能:必须认证了才能访问add和update页面,没有认证直接跳到登录页面

步骤:

1、编写前端页面

①编写首页

<h1>首页</h1>

②编写测试页

(登录首页的时候,通过controller跳到测试页,测试页包含可以跳到add和update页面的超链接) 

<h1>测试页</h1>
<p th:text="${msg}"></p><a th:href="@{/user/add}">add</a><a th:href="@{/user/update}">update</a>

③add页面

<h1>add</h1>
增加一个用户

④update页面

<h1>update</h1>
修改一个用户

⑤登录页

<h1>登录</h1>
<form action="toLogin">用户名:<input type="text" name="username"> <br>密码: <input type="password" name="password"> <br><button type="submit">提交</button>
</form>

2、编写Controller

@Controller
public class MyController {@RequestMapping({"/","/index","/index.html"})public String toIndex(Model model){model.addAttribute("msg","hello,Shiro");return "test";}@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";}
}

3、shiro配置登录拦截

@Configuration
public class ShiroConfig {//ShiroFilterFactoryBean@Beanpublic ShiroFilterFactoryBean getShiroFilterFactoryBean(@Autowired DefaultWebSecurityManager defaultWebSecurityManager){ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();//设置安全管理器bean.setSecurityManager(defaultWebSecurityManager);//添加shiro的内置过滤器/*anon:无需认证就可以访问authc:必须认证了才能访问user:必须拥有 记住我 功能才能访问perms:拥有某个权限才能访问role:拥有某个角色才能访问*/Map<String, String> filterMap = new LinkedHashMap<>();filterMap.put("/user/add", "authc");filterMap.put("/user/update", "authc");bean.setFilterChainDefinitionMap(filterMap);//设置登录的请求bean.setLoginUrl("/toLogin");return bean;}//DefaultWebSecurityManager@Beanpublic DefaultWebSecurityManager getDefaultWebSecurityManager(@Autowired UserRealm userRealm){DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();//关联 UserRealmsecurityManager.setRealm(userRealm);return securityManager;}//创建Realm对象,需要自定义类@Beanpublic UserRealm userRealm(){return new UserRealm();}
}

Shiro实现用户认证

步骤:

1、在 UserRealm中,编写认证方法

    //认证@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {System.out.println("执行了shiro的认证方法");//用户名、密码(要从数据库中获取)String name = "root";String password = "123456";UsernamePasswordToken userToken = (UsernamePasswordToken)token;if(!userToken.getUsername().equals(name)){   //如果userToken中的username和数据库中取出来的name不一样return null;    //抛出异常 UnknownAccountException}//密码认证,shiro做return new SimpleAuthenticationInfo("",password,"");}

2、在controller中封装用户数据

    @RequestMapping("/login")public String login(String username, String password, Model model){//获取当前用户Subject subject = SecurityUtils.getSubject();//封装用户的登录数据UsernamePasswordToken token = new UsernamePasswordToken(username, password);try{subject.login(token);   //执行登录方法,如果没有异常说明就ok了return "index";}catch (UnknownAccountException e){ //用户名不存在model.addAttribute("msg","用户名错误");return "login";}catch (IncorrectCredentialsException e){   //密码不存在model.addAttribute("msg","密码错误");return "login";}}

步骤解析:

 

Shiro整合MyBatis

步骤:

1、导入依赖

        <dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.18</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.0</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency>

2、编写application.yaml和application.properties配置文件

①application.yaml

spring:datasource:username: rootpassword: 123456url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTCdriver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource#Spring Boot 默认是不注入这些属性值的,需要自己绑定#druid 数据源专有配置initialSize: 5minIdle: 5maxActive: 20maxWait: 60000timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: falsepoolPreparedStatements: true#配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入#如果允许时报错  java.lang.ClassNotFoundException: org.apache.log4j.Priority#则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4jfilters: stat,wall,log4jmaxPoolPreparedStatementPerConnectionSize: 20useGlobalDataSourceStat: trueconnectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

②application.properties

mybatis.type-aliases-package=com.pojo
mybatis.mapper-locations=classpath:mapper/*.xml

3、编写实体类

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {private int id;private String name;private String pwd;
}

4、编写mapper层

①UserMapper接口

@Repository
@Mapper
public interface UserMapper {//根据用户名查用户信息public User queryUserByName(String name);
}

②UserMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.UserMapper"><select id="queryUserByName" parameterType="String" resultType="User">select * from mybatis.user where name = #{name};</select>
</mapper>

5、编写service层

①UserService接口

public interface UserService{public User queryUserByName(String name);
}

②UserServiceImpl

@Service
public class UserServiceImpl implements UserService{@AutowiredUserMapper userMapper;@Overridepublic User queryUserByName(String name) {return userMapper.queryUserByName(name);}
}

6、把之前在UserRealm中直接写的name和password,改成从数据库中查出来的

public class UserRealm extends AuthorizingRealm {@AutowiredUserServiceImpl userService;//授权@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {System.out.println("执行了shiro的授权方法");return null;}//认证@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {System.out.println("执行了shiro的认证方法");UsernamePasswordToken userToken = (UsernamePasswordToken)token;//连接真实的数据库User user = userService.queryUserByName(userToken.getUsername());//如果user为空,说明用户不存在if(user == null){return null; //抛异常 UnknownAccountException}//密码认证,shiro做return new SimpleAuthenticationInfo("",user.getPwd(),"");}
}
 

Shiro请求授权实现

1、在ShiroConfig中设置访问哪些路径,需要哪些权限,并配置未授权页面

        filterMap.put("/user/add","perms[user:add]");   //拥有 user:add 权限才能访问/user/addfilterMap.put("/user/update","perms[user:update]");
      bean.setUnauthorizedUrl("/noauth");

 2、在UserRealm中给当前用户授权,其中权限是从数据库中查出来的

    @Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {System.out.println("执行了shiro的授权方法");SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();//拿到当前登录的这个对象Subject subject = SecurityUtils.getSubject();User currentUser  = (User)subject.getPrincipal();   //拿到user对象info.addStringPermission(currentUser.getPerms());return info;}

3、在controller中设置未授权url处理

    @RequestMapping("/noauth")@ResponseBodypublic String unauthorized(){return "未经授权,无法访问此页面";}

Shiro整合Thymeleaf

1、导入依赖

        <!--shiro-thymeleaf整合--><dependency><groupId>com.github.theborakompanioni</groupId><artifactId>thymeleaf-extras-shiro</artifactId><version>2.0.0</version></dependency>

2、在shiroConfig中整合thymeleaf

    //ShiroDialect:用来整合 shiro thymeleaf@Beanpublic ShiroDialect getShiroDialect(){return new ShiroDialect();}

 3、更改前端页面

①在test页面编写一个登录连接

<p><a th:href="@{/toLogin}">登录</a>
</p>

②在首页设置add和update链接,拥有对应权限才可以访问

 shiro命名空间:

xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro"

链接:

<div shiro:hasPermission="user:add"><a th:href="@{/user/add}">add</a>
</div><div shiro:hasPermission="user:update"><a th:href="@{/user/update}">update</a>
</div>

相关文章:

SpringBoot08:Shiro

什么是Shiro&#xff1f; 一个Java的安全&#xff08;权限&#xff09;框架&#xff0c;可以完成认证、授权、加密、会话管理、Web集成、缓存等 下载地址&#xff1a;Apache Shiro | Simple. Java. Security. 快速启动 先在官网找到入门案例&#xff1a;shiro/samples/quick…...

进击中的 Zebec 生态,Web2 与 Web3 世界的连接器

虽然从意识形态上看&#xff0c;Web2世界与Web3世界存在着不同的逻辑&#xff0c;但我们同样看到&#xff0c;随着加密资产领域的发展&#xff0c;其正在作为优质投资品&#xff0c;被以Paypal、高盛等主流机构重视与接受。当然&#xff0c;除了作为投资者品外&#xff0c;近年…...

SpringCloud保姆级搭建教程五---Redis

首先&#xff0c;这个和微服务没有直接的关系&#xff0c;只是在代码开发当中要使用的一个工具而已&#xff0c;为了提高这个系统的性能&#xff0c;加快查询效率等方面而使用它1、首先&#xff0c;要先安装redis到电脑上&#xff0c;这里依然是在windows上演示&#xff0c;之后…...

存储类别、链接与内存管理(一)

1、一些必要的基础概念 &#xff08;1&#xff09;对象 从硬件的角度&#xff0c;被存储的每个值都被占用了一定的物理内存&#xff0c;C语言把这样的一块内存称为对象对象可以存储一个或多个值一个对象可能并未存储实际的值&#xff0c;也可能存储一个或多个值&#xff0c;但…...

JS设计模式

文章目录1 什么是设计模式&#xff1f;2 发布-订阅模式2.1 DOM事件2.2 基于Broadcast Channel实现跨页面通信2.3 基于localStorage实现跨页面通信2.4 使用 Vue 的 EventBus 进行跨组件通信2.4 使用 React 的 EventEmitter 进行跨组件通信3 装饰器模式3.1 React 高阶组件 HOC3.2…...

四、常用样式讲解二

文章目录一、常用样式讲解二1.1 元素隐藏1.2 二级菜单1.3 相对定位和绝对定位1.4 定位的特殊情况1.5 表格1.6 表格的css属性1.7 表格中新增的标签一、常用样式讲解二 1.1 元素隐藏 如何让一个元素隐藏 1、不定义颜色 占用空间 2、display: none 不占用空间 3、visibility: hi…...

KDHX-8700无线高压核相相序表

一、产品简介 KDHX-8700无线高压核相相序表&#xff08;以下简称“仪器”&#xff09;用于测定三相线相序、检测环网或双电源电力网闭环点断路器两侧电源是否同相。在闭环两电源之前一定要进行核相操作&#xff0c;否则可能发生短路。仪器适用于380V&#xff5e;35kV交流输电线…...

【C++提高笔记】泛型编程与STL技术

文章目录模板的概念函数模板函数模板语法函数模板注意事项函数模板案例普通函数与函数模板的调用规则模板的局限性类模板类模板语法类模板与函数模板区别类模板中成员函数创建时机类模板对象做函数参数类模板与继承类模板成员函数类外实现类模板分文件编写类模板与友元类模板案…...

实用机器学习-学习笔记

文章目录9.1模型调参9.1.1思考与总结9.1.2 基线baseline9.1.3SGD ADAM9.1.4 训练代价9.1.5 AUTOML9.1.6 要多次调参管理9.1.7复现实验的困难9.1模型调参 9.1.1思考与总结 1了解了baseline和调参基本原则 2了解了adams和sgd的优劣 3了解了训练树和神经网络的基本代价 4了解了a…...

2023-02-15 学习记录--React-邂逅Redux(二)

React-邂逅Redux&#xff08;二&#xff09; “天道酬勤&#xff0c;与君共勉”——承接React-邂逅Redux&#xff08;一&#xff09;&#xff0c;让我们一起继续探索Redux的奥秘吧~☺️ 一、前言 React-邂逅Redux&#xff08;一&#xff09;让我们对Redux有了初步认识&#xff…...

Framework——【MessageQueue】消息队列

定义 队列是 Apache RocketMQ 中消息存储和传输的实际容器&#xff0c;也是 Apache RocketMQ 消息的最小存储单元。 Apache RocketMQ 的所有主题都是由多个队列组成&#xff0c;以此实现队列数量的水平拆分和队列内部的流式存储。 队列的主要作用如下&#xff1a; 存储顺序性…...

SpringBoot依赖原理分析及配置文件

&#x1f49f;&#x1f49f;前言 ​ 友友们大家好&#xff0c;我是你们的小王同学&#x1f617;&#x1f617; 今天给大家打来的是 SpringBoot依赖原理分析及配置文件 希望能给大家带来有用的知识 觉得小王写的不错的话麻烦动动小手 点赞&#x1f44d; 收藏⭐ 评论&#x1f4c4…...

智慧机场,或将成为航空领域数字孪生技术得完美应用

在《智慧民航建设路线图》文件中&#xff0c;民航局明确指出&#xff0c;智慧机场是实现智慧民航的四个核心抓手之一。这一战略性举措旨在推进数字化技术与航空产业的深度融合&#xff0c;为旅客提供更加智能化、便捷化、安全化的出行服务&#xff0c;进一步提升我国民航发展的…...

SQL64 对顾客ID和日期排序

描述有Orders表cust_idorder_numorder_dateandyaaaa2021-01-01 00:00:00andybbbb2021-01-01 12:00:00bobcccc2021-01-10 12:00:00dickdddd2021-01-11 00:00:00【问题】编写 SQL 语句&#xff0c;从 Orders 表中检索顾客 ID&#xff08;cust_id&#xff09;和订单号&#xff08;…...

MybatisPlus使用聚合函数

前言 今天遇到了一个求总数返回的情况&#xff0c;我一想这不是用sum就完事了吗。 但是仔细想想&#xff0c;MybatisPlus好像没有直接使用sum的api。 虽然没有直接提供&#xff0c;但是办法还是有的&#xff0c;下面就分享下如何实现的&#xff1a; 首先如果使用sql是这么写…...

工程管理系统源码企业工程管理系统简介

一、立项管理 1、招标立项申请 功能点&#xff1a;招标类项目立项申请入口&#xff0c;用户可以保存为草稿&#xff0c;提交。 2、非招标立项申请 功能点&#xff1a;非招标立项申请入口、用户可以保存为草稿、提交。 3、采购立项列表 功能点&#xff1a;对草稿进行编辑&#x…...

《计算机视觉和图像处理简介 - 中英双语版》:使用 OpenCV对图像进行空间滤波

文章大纲 Linear Filtering 线性滤波器Filtering Noise 过滤噪声Gaussian Blur 高斯滤波Image Sharpening 图像锐化Edges 边缘滤波Median 中值滤波Threshold Function Parameters 阈值函数参数References本文大概需要40分钟 Spatial Operations in Image Processing 图像处理中…...

FreeRTOS软件定时器 | FreeRTOS十三

目录 说明&#xff1a; 一、定时器简介 1.1、定时器 1.2、软件定时器 1.3、硬件定时器 1.4、FreeRTOS软件定时器 1.5、软件定时器服务任务作用 1.6、软件定时器的命令队列 1.7、软件定时器相关配置 1.8、单次定时器和周期定时器 1.9、软件定时器结构体 二、软件定时…...

电脑文件被误删?360文件恢复工具,免费的文件恢复软件

电脑里面保存着各种文件&#xff0c;因为误操作我们把还需要用的文件给删除了。很多人都想要使用不收费的文件恢复软件来进行恢复操作&#xff0c;但是又不清楚有哪些文件可以帮到我们。接下来就给大家介绍&#xff0c;一款真正免费的数据 恢复app&#xff0c;一起来看看&#…...

pg_cron优化案例--terminate pg_cron launcher可自动拉起

场景 在PostgreSQL中我们可以使用pg_cron来实现数据库定时任务 我有一个select 1的定时任务&#xff0c;每分钟触发一次 testdb# select * from cron.job ;jobid | schedule | command | nodename | nodeport | database | username | active | jobname -------…...

Python 之 NumPy 随机函数和常用函数

文章目录一、随机函数1. numpy.random.rand(d0,d1,…,dn)2. numpy.random.randn(d0,d1,…,dn)3. numpy.random.normal()4. numpy.random.randint()5. numpy.random.sample6. 随机种子np.random.seed()7. 正态分布 numpy.random.normal二、数组的其他函数1. numpy.resize()2. nu…...

【目标检测】K-means和K-means++计算anchors结果比较(附完整代码,全网最详细的手把手教程)

写在前面: 首先感谢兄弟们的订阅,让我有创作的动力,在创作过程我会尽最大努力,保证作品的质量,如果有问题,可以私信我,让我们携手共进,共创辉煌。 一、介绍 YOLO系列目标检测算法中基于anchor的模型还是比较多的,例如YOLOv3、YOLOv4、YOLOv5等,我们可以随机初始化a…...

Java高手速成 | 图说重定向与转发

我们先回顾一下Servlet的工作原理&#xff0c;Servlet的工作原理跟小猪同学食堂就餐的过程很类似。小猪同学点了烤鸡腿&#xff08;要奥尔良风味的&#xff09;&#xff0c;食堂窗口的服务员记下了菜单&#xff0c;想了想后厨的所有厨师&#xff0c;然后将菜单和餐盘交给专门制…...

Git:不小心在主分支master上进行修改,怎么才能将修改的数据保存到正确的分支中

1.如果还没有push commit 代码第一步&#xff1a;将所修改的代码提交到暂存区git stash第二步&#xff1a;切换到正确的分支git checkout 分支名第三步&#xff1a;从暂存区中取出保存到正确的分支中git stash pop第四步&#xff1a;重新提交git push origin 分支名2.如果已经p…...

都2023年了,如果不会Stream流、函数式编程?你确定能看懂公司代码?

&#x1f473;我亲爱的各位大佬们好&#x1f618;&#x1f618;&#x1f618; ♨️本篇文章记录的为 Stream流、函数式编程 相关内容&#xff0c;适合在学Java的小白,帮助新手快速上手,也适合复习中&#xff0c;面试中的大佬&#x1f649;&#x1f649;&#x1f649;。 ♨️如果…...

亚马逊云科技汽车行业解决方案

当今&#xff0c;随着万物智联、云计算等领域的高速发展&#xff0c;创新智能网联汽车和车路协同技术正在成为车企加速发展的关键途径&#xff0c;推动着汽车产品从出行代步工具向着“超级智能移动终端”快速转变。 挑战无处不在&#xff0c;如何抢先预判&#xff1f; 随着近…...

为什么学了模数电还是看不懂较复杂的电路图

看懂电路并不难。 (1) 首先要摆正心态&#xff0c;不要看到错综复杂的电路图就一脸懵逼&#xff0c;不知所错。你要明白&#xff0c;再复杂的电路也是由一个个的基本电路拼装出来的。 (2) 基础知识当然是少不了的&#xff0c;常用的基本电路结构搞搞清楚。 (3) 分析电路之前先要…...

帮公司面试了一个30岁培训班出来的程序员,没啥工作经验...

首先&#xff0c;我说一句&#xff1a;培训出来的&#xff0c;优秀学员大有人在&#xff0c;我不希望因为带着培训的标签而无法达到用人单位和候选人的双向匹配&#xff0c;是非常遗憾的事情。 最近&#xff0c;在网上看到这样一个留言&#xff0c;引发了程序员这个圈子不少的…...

勒索软件、网络钓鱼、零信任和网络安全的新常态

当疫情来袭时&#xff0c;网络罪犯看到了他们的机会。随着公司办公、政府机构、学校和大学从以往的工作模式转向远程线上办公模式&#xff0c;甚至许多医疗保健设施都转向线上&#xff0c;这种快速的过渡性质导致了不可避免的网络安全漏洞。消费者宽带和个人设备破坏了企业安全…...

python3 字符串拼接与抽取

我们经常会有对字符串进行拼接和抽取的需求&#xff0c;下面有几个例子可以作为参考。 需求1&#xff1a;取出ip地址的网络地址与网络掩码进行拼接&#xff0c;分别使用shell脚本和python3实现 # echo "192.168.0.1"|awk -F. {print $1"."$2"."…...