当前位置: 首页 > 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 -------…...

springboot 百货中心供应链管理系统小程序

一、前言 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;百货中心供应链管理系统被用户普遍使用&#xff0c;为方…...

爬虫基础学习day2

# 爬虫设计领域 工商&#xff1a;企查查、天眼查短视频&#xff1a;抖音、快手、西瓜 ---> 飞瓜电商&#xff1a;京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空&#xff1a;抓取所有航空公司价格 ---> 去哪儿自媒体&#xff1a;采集自媒体数据进…...

图表类系列各种样式PPT模版分享

图标图表系列PPT模版&#xff0c;柱状图PPT模版&#xff0c;线状图PPT模版&#xff0c;折线图PPT模版&#xff0c;饼状图PPT模版&#xff0c;雷达图PPT模版&#xff0c;树状图PPT模版 图表类系列各种样式PPT模版分享&#xff1a;图表系列PPT模板https://pan.quark.cn/s/20d40aa…...

【数据分析】R版IntelliGenes用于生物标志物发现的可解释机器学习

禁止商业或二改转载&#xff0c;仅供自学使用&#xff0c;侵权必究&#xff0c;如需截取部分内容请后台联系作者! 文章目录 介绍流程步骤1. 输入数据2. 特征选择3. 模型训练4. I-Genes 评分计算5. 输出结果 IntelliGenesR 安装包1. 特征选择2. 模型训练和评估3. I-Genes 评分计…...

Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信

文章目录 Linux C语言网络编程详细入门教程&#xff1a;如何一步步实现TCP服务端与客户端通信前言一、网络通信基础概念二、服务端与客户端的完整流程图解三、每一步的详细讲解和代码示例1. 创建Socket&#xff08;服务端和客户端都要&#xff09;2. 绑定本地地址和端口&#x…...

让回归模型不再被异常值“带跑偏“,MSE和Cauchy损失函数在噪声数据环境下的实战对比

在机器学习的回归分析中&#xff0c;损失函数的选择对模型性能具有决定性影响。均方误差&#xff08;MSE&#xff09;作为经典的损失函数&#xff0c;在处理干净数据时表现优异&#xff0c;但在面对包含异常值的噪声数据时&#xff0c;其对大误差的二次惩罚机制往往导致模型参数…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖

在Vuzix M400 AR智能眼镜的助力下&#xff0c;卢森堡罗伯特舒曼医院&#xff08;the Robert Schuman Hospitals, HRS&#xff09;凭借在无菌制剂生产流程中引入增强现实技术&#xff08;AR&#xff09;创新项目&#xff0c;荣获了2024年6月7日由卢森堡医院药剂师协会&#xff0…...

AI+无人机如何守护濒危物种?YOLOv8实现95%精准识别

【导读】 野生动物监测在理解和保护生态系统中发挥着至关重要的作用。然而&#xff0c;传统的野生动物观察方法往往耗时耗力、成本高昂且范围有限。无人机的出现为野生动物监测提供了有前景的替代方案&#xff0c;能够实现大范围覆盖并远程采集数据。尽管具备这些优势&#xf…...

华为OD机试-最短木板长度-二分法(A卷,100分)

此题是一个最大化最小值的典型例题&#xff0c; 因为搜索范围是有界的&#xff0c;上界最大木板长度补充的全部木料长度&#xff0c;下界最小木板长度&#xff1b; 即left0,right10^6; 我们可以设置一个候选值x(mid)&#xff0c;将木板的长度全部都补充到x&#xff0c;如果成功…...

在 Spring Boot 中使用 JSP

jsp&#xff1f; 好多年没用了。重新整一下 还费了点时间&#xff0c;记录一下。 项目结构&#xff1a; pom: <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://ww…...