SpringSecurity(一):权限管理设计与实现(官文英解+源码调试+基本环境搭建)

news2024/9/22 15:39:16

权限管理设计与实现

    • 前言
    • 权限管理
      • 认证
      • 授权
      • 安全管理框架
    • 整体架构
      • 认证
        • AuthenticationManager
        • Authentication
        • SecurityContextHolder
      • 授权
        • AccessDecisionManager
        • AccessDecisionVoter
        • ConfigAttribute
    • 环境搭建
      • 技术栈
      • 创建项目
      • 整合Spring Security
    • 实现原理
      • 官方文档解读
        • A Review of Filters
        • DelegatingFilterProxy
          • 为什么会有DelegatingFileterProxy的出现?
          • DelegatingFileterProxy如何将Servlet容器和Spring的ApplicationContext进行桥接?
          • DelegatingFilterProxy的好处都有什么?
        • FilterChainProxy
          • 为什么会有FilterChainProxy的出现
        • SecurityFilterChain
          • SecurityFilterChain和FilterChainProxy区别在哪
      • Security Filters
    • 结尾

前言

内容是根据b站视频黑马作为一个引子,期间不断的翻阅书和查官网的英语文档一句句翻译过来的,相信能做到相对来说全一些,当时学完收获还是很大的,目前整理的时候又回头翻看,收获还是有的,希望也可以帮助到你,目前不断更新,有时间就来补充了,内容整理比较辛苦,码字不易,希望点个关注一起进步。

权限管理

涉及到用户参与到系统都需要进行权限管理,权限管理实现了对用户访问系统的控制,按照安全规则或者安全策略去控制用户可以访问且只能访问自己被授权的资源
权限管理包括用户身份认证授权两部分,简称认证授权。
对于需要访问控制的资源用户首先进行身份认证,认证通过后用户具有改资源的访问权限方可访问。

认证

身份认证就是判断一个用户是否为合法用户的处理过程。
最简单的方式:系统核对用户的用户名和口令是否与系统中一致。

授权

授权就是访问控制,控制不同身份可以访问到哪些资源。

安全管理框架

Java企业级开发中,安全管理框架非常少,目前比较常见的是:

  • Shiro
  • Spring Security
  • 开发者自定义

整体架构

在架构设计中,认证授权是分开的,两个是独立的存在,好处在于可以非常方便的整合一些外部的解决方案。
在这里插入图片描述
下面我们对于里面的细节做一些基本的了解。

认证

认证这块更到后面好好和大家聊聊

AuthenticationManager

Authentication

SecurityContextHolder

授权

AccessDecisionManager

AccessDecisionVoter

ConfigAttribute

环境搭建

技术栈

  • spring boot
  • spring security

创建项目

1.创建springboot单体项目
请添加图片描述
2. 创建controller
项目结构:
请添加图片描述
项目代码:

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        System.out.println("hello security");
        return "hello spring security";
    }
}

3.启动项目测试
如果和我的配置是一样的,默认端口是8080,那么就行下面这个地址:http://localhost:8080/hello
在这里插入图片描述

整合Spring Security

  1. 引入spring security相关依赖
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

2.再次启动项目

  • 启动后控制台生成一个密码
  • 访问hello发现直接跳转到登陆页面
    请添加图片描述
    在这里插入图片描述
    3.登陆系统
  • 默认用户名:user
  • 默认密码:控制台打印的uuid
    请添加图片描述

看到这相信你能体会到它的强大,只需引入一个依赖,所有的接口都会自动保护起来!
思考一下:

  • 为什么引⼊ Spring Security 之后没有任何配置所有请求就要认证呢?
  • 在项⽬中明明没有登录界⾯,登录界⾯怎么来的呢?
  • 为什么使⽤user和控制台密码能登陆,登录时验证数据源存在哪⾥呢?

实现原理

虽然开发者只需要引⼊⼀个依赖,就可以让 Spring Security 对应⽤进⾏保护。Spring Security ⼜是如何做到的呢?
在 Spring Security 中认证、授权等功能都是基于过滤器完成的。

假设我们现在不用Spring Security,自己去开发一个权限管理,我们应该如何做权限管理?
需求:我们希望在访问一个资源的时候,先认证再访问,如果没有认证,则先要去做认证。
那么我们的设计思路应该如下图所示:请添加图片描述提供一个官方的网址来参考:https://docs.spring.io/spring-security/site/docs/5.5.x-SNAPSHOT/reference/html5/#servlet-architecture

官方文档解读

A Review of Filters

Spring Security’s Servlet support is based on Servlet Filters, so it is helpful to look at the role of Filters generally first. 
The picture below shows the typical layering of the handlers for a single HTTP request.

翻译:
SpringSecurity的Servlet的支持是基于Servlet过滤器的,所以先看一下过滤器的作用对我们比较有帮助。
下图展示了过滤器处理单个HTTP请求到来时的典型分层。

图一:过滤链

The client sends a request to the application, and the container creates a FilterChain which contains the Filters and Servlet that should process the HttpServletRequest based on the path of the request URI. 
In a Spring MVC application the Servlet is an instance of DispatcherServlet. 
At most one Servlet can handle a single HttpServletRequest and HttpServletResponse. 

翻译:
客户端向应用程序发送一个请求,容器创建一个过滤链,它包含过滤器和Servlet,它们根据请求的URL路径来处理HttpServletRequest。
在Spring MVC应用程序中,Servlet是DispatcherServlet的一个实例。
每个HttpServletRequest和HttpServletResponse只能被一个Servlet处理。
However, more than one Filter can be used to:
1. Prevent downstream Filters or the Servlet from being invoked. 
In this instance the Filter will typically write the HttpServletResponse.
2. Modify the HttpServletRequest or HttpServletResponse used by the downstream Filters and Servlet
The power of the Filter comes from the FilterChain that is passed into it.

翻译:
然而,可以使用多个过滤器来实现以下功能:
1. 阻止下游的过滤器或Servlet被调用.
在这种情况下,过滤器通常会编写HttpServletResponse。
2. 可以修改下游的过滤器和Servlet所使用的HttpServletRequest或HttpServletResponse。
过滤器的强大之处来自于过滤链所传递给它的。

DelegatingFilterProxy

Spring provides a Filter implementation named DelegatingFilterProxy that allows bridging between the Servlet container’s lifecycle and Spring’s ApplicationContext. 
The Servlet container allows registering Filters using its own standards, but it is not aware of Spring defined Beans. 
DelegatingFilterProxy can be registered via standard Servlet container mechanisms, but delegate all the work to a Spring Bean that implements Filter.

翻译:
Spring提供了一个名为DelegatingFilterProxy的过滤器实现,它被允许在Servlet容器的生命周期和Spring的ApplicationContext之间建立桥接。(Delegating:授权|委托)
Servlet容器允许使用自己的标准注册过滤器,但它不知道Spring定义的Bean。
DelegatingFilterProxy可以通过标准的Servlet容器机制进行注册,但它会将所有的工作委托给一个实现了Filter接口的Spring Bean。

这是DelegatingFilterProxy如何与过滤器和FilterChain相结合的示意图,如下图:
在这里插入图片描述

DelegatingFilterProxy looks up Bean Filter0 from the ApplicationContext and then invokes Bean Filter0.
The pseudo code of DelegatingFilterProxy can be seen below.

翻译:
DelegatingFilterProxy会从ApplicationContext中查找名为Filter0的Bean,
然后调用该Bean。下面是DelegatingFilterProxy的伪代码示例
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
    // Lazily get Filter that was registered as a Spring Bean
    // For the example in DelegatingFilterProxy delegate is an instance of Bean Filter0
    Filter delegate = getFilterBean(someBeanName);
    // delegate work to the Spring Bean
    delegate.doFilter(request, response);
}
 Another benefit of DelegatingFilterProxy is that it allows delaying looking Filter bean instances. 
 This is important because the container needs to register the Filter instances before the container can startup. 
 However, Spring typically uses a ContextLoaderListener to load the Spring Beans which will not be done until after the Filter instances need to be registered.

翻译:
DelegatingFilterProxy的另一个好处是它允许延迟查找过滤器Bean实例。
这一点很重要,因为容器需要在启动之前注册过滤器实例。
然而,Spring通常使用ContextLoaderListener来加载Spring Beans,而这个操作在过滤器实例需要注册之前是不会执行的。

那么看完官方文档后,总结一下:

为什么会有DelegatingFileterProxy的出现?

主要是为了解决Spring应用程序中的过滤器集成和管理的需求。
在传统的Servlet容器中,过滤器是通过容器的标准机制进行注册和管理的,而与Spring的ApplicationContext没有直接的集成。

由于Spring框架提供了丰富的依赖注入、生命周期管理和其他高级特性,开发人员希望能够在Spring应用程序中更好地利用这些特性来管理过滤器。他们希望能够像管理其他Spring Bean一样管理过滤器,而不仅仅局限于Servlet容器的机制。

因此,DelegatingFilterProxy就应运而生了。它作为一个代理过滤器,将Servlet容器和Spring的ApplicationContext进行桥接,实现了过滤器在Spring环境中的管理和配置。通过DelegatingFilterProxy,开发人员可以使用Spring的依赖注入、生命周期管理等功能,以及利用Spring Bean的灵活性和控制能力来编写和管理过滤器。

DelegatingFilterProxy的出现使得过滤器的集成和管理更加灵活、高效,并且能够充分利用Spring框架的优势。它为我们提供了一种统一、一致的方式来管理过滤器,并将过滤器的实现与Servlet容器的机制解耦,使得Spring应用程序的过滤器配置更加方便、可扩展和易于维护。

DelegatingFileterProxy如何将Servlet容器和Spring的ApplicationContext进行桥接?
  1. 在Servlet容器中注册DelegatingFilterProxy:首先,开发人员在web.xml或Servlet容器的其他配置文件中注册DelegatingFilterProxy作为一个过滤器。这是通过使用Servlet容器的标准机制进行注册,就像注册其他过滤器一样。
  2. DelegatingFilterProxy初始化:在Servlet容器启动时,DelegatingFilterProxy将被实例化并初始化。它会获取应用程序的ApplicationContext,通常是通过ContextLoaderListener或其他Spring配置来加载。
  3. 查找目标过滤器Bean:DelegatingFilterProxy在初始化阶段会从ApplicationContext中查找指定的目标过滤器Bean。这个目标过滤器Bean是开发人员定义的实际过滤器实现,它实现了Spring的Filter接口。
  4. 运行过滤器链:当收到请求时,DelegatingFilterProxy会将请求和响应传递给目标过滤器Bean的doFilter方法。目标过滤器Bean可以执行自定义的过滤逻辑,并通过调用FilterChain的doFilter方法将请求传递给下一个过滤器或Servlet。
    举个栗子🌰:
    1.实现一个Filter接口的自定义过滤器类:
import javax.servlet.*;
import java.io.IOException;

public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 过滤器初始化逻辑
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // 过滤器逻辑处理
        // ...

        // 继续调用下一个过滤器或Servlet
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        // 过滤器销毁逻辑
    }
}

2.在Spring的配置文件(如applicationContext.xml)中配置DelegatingFilterProxy和自定义过滤器的Bean:

<bean id="myFilter" class="com.example.MyFilter" />

<bean id="delegatingFilterProxy" class="org.springframework.web.filter.DelegatingFilterProxy">
    <property name="targetBeanName" value="myFilter" />
</bean>

3.在web.xml中注册DelegatingFilterProxy:

<filter>
    <filter-name>delegatingFilterProxy</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>delegatingFilterProxy</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

通过以上配置,DelegatingFilterProxy将会在应用程序启动时被实例化,并根据targetBeanName属性查找并委托给MyFilter过滤器的处理逻辑。
这样,我们就实现了通过DelegatingFilterProxy将Servlet容器和Spring的ApplicationContext进行桥接,从而能够在Spring应用程序中管理和配置自定义过滤器。

DelegatingFilterProxy的好处都有什么?
  1. 无缝集成Spring和Servlet容器:DelegatingFilterProxy允许在Servlet容器中注册过滤器,同时将实际的过滤逻辑委托给Spring中的Bean。这样可以充分利用Spring的依赖注入、生命周期管理和其他特性,将过滤器与Spring应用程序无缝集成。

  2. 延迟加载过滤器Bean:DelegatingFilterProxy允许延迟查找过滤器Bean的实例。这对于需要在容器启动之前注册过滤器实例非常重要。通过DelegatingFilterProxy,可以将过滤器的实例化推迟到需要使用时,避免因为Bean的加载顺序问题而导致注册失败。

  3. 更好的控制和灵活性:DelegatingFilterProxy允许使用Spring的ApplicationContext来获取过滤器Bean实例。这意味着可以在Spring的IoC容器中配置和管理过滤器,以及利用Spring的各种特性,如AOP切面、事务管理等。这为过滤器的控制和定制提供了更多的灵活性和扩展性。

  4. 代码重用和模块化:通过DelegatingFilterProxy,可以将具体的过滤逻辑封装在Spring的Bean中,从而实现代码的重用和模块化。不同的过滤器可以共享同一个Spring Bean,并在配置中指定不同的过滤器名称。这样可以避免代码的冗余和重复编写,提高代码的可维护性和可扩展性。

FilterChainProxy

Spring Security’s Servlet support is contained within FilterChainProxy. 
FilterChainProxy is a special Filter provided by Spring Security that allows delegating to many Filter instances through SecurityFilterChain.
Since FilterChainProxy is a Bean, it is typically wrapped in a DelegatingFilterProxy.

翻译:
Spring Security的Servlet支持是由FilterChainProxy组件提供的。
FilterChainProxy是由Spring Security提供的特殊过滤器,通过SecurityFilterChain实现了将请求委托给多个过滤器实例的功能。
由于FilterChainProxy是一个Bean,通常会将其包装在一个DelegatingFilterProxy中。

下图展示了FilterChainProxy的信息:
在这里插入图片描述

为什么会有FilterChainProxy的出现

FilterChainProxy的出现主要是为了实现灵活且可配置的安全过滤器链管理
在Web应用程序中,安全性是一个重要的方面,需要对请求进行身份验证、授权和其他安全操作。为了实现这些安全功能,需要使用多个过滤器来处理不同的安全任务。
然而,每个过滤器通常只能处理特定的安全任务,例如身份验证或授权。而在实际的应用程序中,可能需要使用不同的过滤器来处理不同的URL路径、请求条件或安全需求。此外,过滤器的顺序和执行流程也可能因应用程序的特定需求而有所不同。
为了解决这些灵活性和可配置性的问题,Spring Security引入了FilterChainProxy。
FilterChainProxy允许我们根据特定的URL路径、请求条件或安全需求,配置多个过滤器链并指定它们的顺序和执行流程。通过FilterChainProxy,可以动态地选择适当的过滤器链来处理不同的请求,并按照预定义的顺序依次执行过滤器。
FilterChainProxy的出现使得安全过滤器链的管理更加灵活、可配置和易于扩展。它提供了一种集中管理和调度多个过滤器的机制,将请求路由到适当的过滤器链中,并确保按照指定的顺序执行。同时,它还提供了嵌套过滤器链的支持,使得可以构建复杂的安全逻辑。

SecurityFilterChain

SecurityFilterChain is used by FilterChainProxy to determine which Spring Security Filters should be invoked for this request.

翻译:
FilterChainProxy使用SecurityFilterChain来确定在该请求中应该调用哪些Spring Security过滤器。

如下图所示:
在这里插入图片描述

The Security Filters in SecurityFilterChain are typically Beans, but they are registered with FilterChainProxy instead of DelegatingFilterProxy. 
FilterChainProxy provides a number of advantages to registering directly with the Servlet container or DelegatingFilterProxy. 
First, it provides a starting point for all of Spring Security’s Servlet support. 
For that reason, if you are attempting to troubleshoot Spring Security’s Servlet support, adding a debug point in FilterChainProxy is a great place to start.

翻译:
SecurityFilterChain中的安全过滤器通常是Spring的Bean,但它们是通过FilterChainProxy进行注册,而不是通过DelegatingFilterProxy进行注册。

通过FilterChainProxy直接注册,相比于直接在Servlet容器或DelegatingFilterProxy中注册,提供了一些优势。

首先,它为Spring Security的所有Servlet支持提供了一个起点。
因此,如果您正在尝试排除Spring Security的Servlet支持问题,向FilterChainProxy添加一个调试断点是一个很好的起点。(to troubleshoot :进行故障排除)

Second, since FilterChainProxy is central to Spring Security usage it can perform tasks that are not viewed as optional.
For example, it clears out the SecurityContext to avoid memory leaks. 
It also applies Spring Security’s HttpFirewall to protect applications against certain types of attacks.
翻译:
第二,由于FilterChainProxy在Spring Security的使用中扮演着核心角色,它可以执行一些被视为非可选的任务。
例如,它清除SecurityContext以避免内存泄漏。
它还应用Spring Security的HttpFirewall以保护应用程序免受某些类型的攻击。


In addition, it provides more flexibility in determining when a SecurityFilterChain should be invoked. 
In a Servlet container, Filters are invoked based upon the URL alone.
However, FilterChainProxy can determine invocation based upon anything in the HttpServletRequest by leveraging the RequestMatcher interface.

翻译:
此外,它在确定何时应调用SecurityFilterChain时提供了更大的灵活性。
在Servlet容器中,过滤器的调用是基于URL的。
然而,FilterChainProxy可以通过利用RequestMatcher接口,根据HttpServletRequest中的任何内容来确定调用方式。

In fact, FilterChainProxy can be used to determine which SecurityFilterChain should be used. 
This allows providing a totally separate configuration for different slices of your application.

翻译:
事实上,FilterChainProxy可以用来确定应该使用哪个SecurityFilterChain。
这样可以为应用程序的不同部分提供完全独立的配置。

在这里插入图片描述

In the Multiple SecurityFilterChain Figure FilterChainProxy decides which SecurityFilterChain should be used. 
Only the first SecurityFilterChain that matches will be invoked. 
If a URL of /api/messages/ is requested, it will first match on SecurityFilterChain0's pattern of /api/**, so only SecurityFilterChain0 will be invoked even though it also matches on SecurityFilterChainn.
If a URL of /messages/ is requested, it will not match on SecurityFilterChain0's pattern of /api/**, so FilterChainProxy will continue trying each SecurityFilterChain. 
Assuming that no other, SecurityFilterChain instances match SecurityFilterChainn will be invoked.

翻译:
在多个SecurityFilterChain的图示中,FilterChainProxy决定使用哪个SecurityFilterChain。
只有第一个匹配的SecurityFilterChain会被调用。
如果请求的URL是/api/messages/,它将首先匹配到SecurityFilterChain0的模式/api/**,因此只有SecurityFilterChain0会被调用,即使它也匹配SecurityFilterChainn。
如果请求的URL是/messages/,它不会匹配到SecurityFilterChain0的模式/api/**,因此FilterChainProxy将继续尝试每个SecurityFilterChain。
假设没有其他的SecurityFilterChain实例与之匹配,那么SecurityFilterChainn将被调用。

Notice that SecurityFilterChain0 has only three security Filters instances configured.
However, SecurityFilterChainn has four security Filters configured. 
It is important to note that each SecurityFilterChain can be unique and configured in isolation. 
In fact, a SecurityFilterChain might have zero security Filters if the application wants Spring Security to ignore certain requests.
SecurityFilterChain和FilterChainProxy区别在哪

SecurityFilterChain和FilterChainProxy是Spring Security中用于处理安全过滤器链的两个关键组件。

  • SecurityFilterChain是一个接口,用于定义一组安全过滤器链。
    每个SecurityFilterChain都包含了一系列的过滤器,用于处理特定的请求或URL路径。它定义了一个方法boolean matches(HttpServletRequest request),用于确定当前请求是否与该过滤器链匹配。当请求匹配到某个SecurityFilterChain时,其中的过滤器将被调用以完成安全处理。

  • FilterChainProxy是Spring Security提供的特殊过滤器,用于管理和调度多个SecurityFilterChain。
    它充当了整个安全过滤器链的入口点,并根据请求的特征选择合适的SecurityFilterChain来处理请求。FilterChainProxy是一个Servlet过滤器,通过实现javax.servlet.Filter接口来处理请求和响应,并根据配置的SecurityFilterChain来调用相应的安全过滤器链。

因此,SecurityFilterChain是定义安全过滤器链的接口,而FilterChainProxy是实现了该接口的特殊过滤器,用于管理和调度多个SecurityFilterChain。
FilterChainProxy充当了整个安全过滤器链的代理,根据请求特征选择合适的过滤器链进行处理。

Security Filters

Spring Security 中给我们提供那些过滤器? 默认情况下那些过滤器会被加载呢?
看一下官方文档的描述:

 The Security Filters are inserted into the FilterChainProxy with the SecurityFilterChain API.
 The order of Filters matters.
 It is typically not necessary to know the ordering of Spring Security’s Filters. 
 However, there are times that it is beneficial to know the ordering
Below is a comprehensive list of Spring Security Filter ordering:

翻译:
安全过滤器通过SecurityFilterChain的API被插入到FilterChainProxy中。
过滤器的顺序很重要。
通常情况下,不需要知道Spring Security过滤器的顺序。
然而,有时候了解过滤器的顺序是有益的。
下面是Spring Security过滤器的全面排序列表:

请添加图片描述

结尾

6月底前这个系列肯定更完,大家感兴趣可以种草🥹

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/659266.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Jmeter多接口测试之参数传递

目录 前言&#xff1a; 接口示例 正则表达式提取器 正则表达式提取实例 Json提取器 Json提取器实例 前言&#xff1a; 在进行多接口测试时&#xff0c;有些情况下需要将前一个接口返回数据作为后一个接口的参数&#xff0c;以模拟实际场景。JMeter作为一款常用的性能测试…

【百问百答】可靠性基础知识第六期

1.跌落试验需要确认哪些试验条件? 试验条件包括&#xff1a;释放高度&#xff0c;释放方法和试验表面。 2.什么是跌落试验的试验表面? 试验表面应该是混凝土或者是钢制的平滑坚硬的刚性表面&#xff0c;必要时&#xff0c;可按照相关规范规定其他表面。 3.什么是跌落高度? 指…

云安全技术(二)之云计算参考架构

云计算参考架构 1.1 描述云计算参考架构 Describe Cloud Reference Architecture 多个主要组件组合在一起形成云架构(Cloud Architecture)和云实现的全貌。涉及的组件包括管理和运营云环境的活动(Activity)、角色(Role)和能力(Capability)&#xff0c;以及基于云托管和服务交…

CSDN如何快速获得粉丝和高质量铁粉

✅作者简介&#xff1a;人工智能专业本科在读&#xff0c;喜欢计算机与编程&#xff0c;写博客记录自己的学习历程。 &#x1f34e;个人主页&#xff1a;小嗷犬的个人主页 &#x1f34a;个人网站&#xff1a;小嗷犬的技术小站 &#x1f96d;个人信条&#xff1a;为天地立心&…

Linux:DNS服务(bind)

目录 环境 主服务器和从服务器的配置环境 主服务器 从服务器 主DNS配置文件 dns从服务器配置 环境 如果你只需要主dns服务器那么你只需要挑着主dns服务器配置看即可 我这里使用了4台虚拟机&#xff0c;你也可以不使用这么多根据你的电脑性能去调整 他们必须要在同一个网段…

什么是渗透测试?渗透等于入侵?

什么是渗透测试&#xff1f; 渗透测试 (penetration test)并没有一个标准的定义&#xff0c;国外一些安全组织达成共识的通用说法是&#xff1a;渗透测试是通过模拟恶意黑客的攻击方法&#xff0c;来评估计算机网络系统安全的一种评估方法。这个过程包括对系统的任何弱点、技术…

6.5 this关键字

1. 关键字&#xff1a;this 1.1 this 是什么&#xff1f; 首先。this在Java中是一个关键字&#xff0c;this 指代的是本类的引用对象 1.2 什么时候使用 this 1.2.1 实例方法或构造器中使用当前对象的成员 1、在实例方法或构造器中&#xff0c;我们在使用get和set方法中使用…

Nucleo-F411RE (STM32F411)LL库体验 9 - RT-Thread nano的移植

Nucleo-F411RE &#xff08;STM32F411&#xff09;LL库体验 9 - RT-Thread nano的移植 1、RT-Thread下载 这一节基于rt-thread nano版本&#xff0c;进行内核的移植&#xff0c;不包含任何组件。移植成功后&#xff0c;可创建任务&#xff0c;串口输出RT-Thread版本信息。 …

【Nginx】Nginx操作命令

Nginx操作命令 1.Nginx原生命令1.1 官方文档1.2 找到命令执行文件1.3 介绍基本操作命令1.3.1 命令帮助1.3.2 启动Nginx1.3.3 Nginx停止、重新加载配置文件&#xff1a;-s signal1.3.4 Nginx查看版本、测试配置文件正确性&#xff1a;-s signal 2.使用系统控制命令 systemctl3.补…

【Unity3D】激光雷达特效

1 由深度纹理重构世界坐标 屏幕深度和法线纹理简介中对深度和法线纹理的来源、使用及推导过程进行了讲解&#xff0c;本文将介绍使用深度纹理重构世界坐标的方法&#xff0c;并使用重构后的世界坐标模拟激光雷达特效。 本文完整资源见→Unity3D激光雷达特效。 1&#xff09;重构…

C++linux高并发服务器项目实践 day12

Clinux高并发服务器项目实践 day12 socket介绍字节序字节序转换函数 socket地址IP地址转换(字符串ip-整数&#xff0c;主机、网络字节序的转换)TCP通信流程套接字函数TCP三次握手TCP滑动窗口TCP四次挥手 socket介绍 socket是网络环境中进程间通信的API&#xff0c;也是可以被命…

CAPL如何仿真ARP报文

文章目录 前言一、环境搭建二、IG生成器仿真ARP报文三、CAPL仿真ARP报文前言 随着智能电动汽车的普及,车载以太网的应用逐渐广泛,所以在汽车电子台架测试过程中,免不了仿真模拟发送以太网报文,本文就介绍两种方法模拟仿真发送以太网ARP报文。 一、环境搭建 CANoe安装 VN5…

FPGA时序约束--实战篇(Vivado添加时序约束)

前面几篇文章已经详细介绍了FPGA时序约束基础知识以及常用的时序约束命令&#xff0c;相信大家已经基本掌握了时序约束的方法。 今天介绍一下&#xff0c;如何在Vivado中添加时序约束&#xff0c;Vivado添加约束的方法有3种&#xff1a;xdc文件、时序约束向导&#xff08;Cons…

vue基础-全选,使用计算属性 和 every遍历数组的返回值 true or false

购物车--计算购物车价格 1、计算属性--只要被依赖的数据 发生变化&#xff0c;结果就会变化 2、全选实现 根据选项&#xff0c;动态计算出布尔值&#xff0c;通过计算属性 得到布尔值&#xff1a; 通过every遍历数组list&#xff0c;只要所有 都满足 item > item.goods_s…

递推算法介绍

递推算法 给定一个数的序列H0,H1,…,Hn,…若存在整数n0&#xff0c;使当n>n0时,可以用等号(或大于号、小于号)将Hn与其前面的某些项Hi(0<i<n)联系起来&#xff0c;这样的式子就叫做递推关系。 递推算法是一种简单的算法&#xff0c;即通过已知条件&#xff0c;利用特…

CVPR 2023|EfficientViT:让ViT更高效部署实现实时推理(附源码)

点击蓝字 关注我们 关注并星标 从此不迷路 计算机视觉研究院 公众号ID&#xff5c;计算机视觉研究院 学习群&#xff5c;扫码在主页获取加入方式 论文地址&#xff1a;https://arxiv.org/pdf/2305.07027.pdf 项目代码&#xff1a;https://github.com/microsoft/Cream/tree/main…

打通B端企业私域运营体系:海康威视企业公众号矩阵一探究竟

B端企业私域运营体系的打造需要全新的思路和流程重构&#xff0c;要紧紧围绕B端客户的需求和特性来构建矩阵号&#xff0c;而且要时刻意识到与C端私域运营的巨大差异。 B端企业的获客是一个大部分企业都十分关注但难以提升的部分&#xff0c;传统B端企业的营销以百度等在线渠道…

candence:常见表贴焊盘绘制举例

常见表贴焊盘绘制举例 一、先来看看X7R电容的相关信息 以贴装瓷片电容X7R系列为例 1、误差范围&#xff1a; 2、尺寸大小 3、推荐焊盘尺寸 二、绘制 0603 (inch) 电容的焊盘 下面开始绘制焊盘&#xff1a; 1、 双击打开Pad Designer 2、设置单位等。 3、 点击"LAYER&…

GeSciLiVis | 想知道你感兴趣的基因有多少人在研究吗!?用这个包来解决吧!!!~

1写在前面 天气好热啊&#xff0c;我这里还下着大暴雨&#xff01;~&#x1f625; 不知道各位小伙伴那里的温度怎么样&#xff0c;端午临近&#xff0c;各位有假期吗&#xff01;&#xff1f;&#x1f618; 换组后工作轻松了不少&#xff0c;也有时间做点自己的事情了。&#x…

JDK8-2-流(2.1)- 流操作-distinct

JDK8-2-流&#xff08;2.1&#xff09;- 流操作-distinct 去重操作&#xff0c;如下开头两个菜品一样&#xff0c;对 menu 去重如下&#xff1a; public class DishDistinctTest1 {public static final List<Dish> menu Arrays.asList(new Dish("pork", fal…