SpringBoot+拦截器(Interceptor)

news2025/1/24 17:45:32

记录一下SpringBoot的拦截器(Interceptor)使用

拦截器(Interceptor)是AOP面向切面编程的思想来实现的,对于只写代码的来说,具体如何实现不需要多关心,只需要关心如何去使用,会用在那些地方。

当http请求进入Springboot应用程序后,会去调用 Controller 层,在进入Controller处理应用业务之前,这个请求是需要通过经过拦截器(Interceptor)的,可能是一个也可能是多个,根据需求来,在Controller处理完业务逻辑之后,也要经过拦截器(Interceptor),最终将结果返回给请求着,即使不返回,也会经过的。

在拦截器(Interceptor)中,最常的应用有几个方面

1.校验token(最常用):根据请求token拦截校验是否允许访问特定资源 比如用户列表,开放的请求地址url需要额外的拦截器配置 比如登录
2.记录日志: 记录请求信息的日志数据
3.数据统计: 统计请求某一资源的次数,统计请求进入到响应的处理时间等
4.其他一些实际需求的功能

目前使用的是SpringBoot2.0.5版本

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.5.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

自定义 Interceptor一般是实现 org.springframework.web.servlet.HandlerInterceptor接口
myw
源码是这样的

/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.lang.Nullable;
import org.springframework.web.method.HandlerMethod;

/**
 * Workflow interface that allows for customized handler execution chains.
 * Applications can register any number of existing or custom interceptors
 * for certain groups of handlers, to add common preprocessing behavior
 * without needing to modify each handler implementation.
 *
 * <p>A HandlerInterceptor gets called before the appropriate HandlerAdapter
 * triggers the execution of the handler itself. This mechanism can be used
 * for a large field of preprocessing aspects, e.g. for authorization checks,
 * or common handler behavior like locale or theme changes. Its main purpose
 * is to allow for factoring out repetitive handler code.
 *
 * <p>In an asynchronous processing scenario, the handler may be executed in a
 * separate thread while the main thread exits without rendering or invoking the
 * {@code postHandle} and {@code afterCompletion} callbacks. When concurrent
 * handler execution completes, the request is dispatched back in order to
 * proceed with rendering the model and all methods of this contract are invoked
 * again. For further options and details see
 * {@code org.springframework.web.servlet.AsyncHandlerInterceptor}
 *
 * <p>Typically an interceptor chain is defined per HandlerMapping bean,
 * sharing its granularity. To be able to apply a certain interceptor chain
 * to a group of handlers, one needs to map the desired handlers via one
 * HandlerMapping bean. The interceptors themselves are defined as beans
 * in the application context, referenced by the mapping bean definition
 * via its "interceptors" property (in XML: a &lt;list&gt; of &lt;ref&gt;).
 *
 * <p>HandlerInterceptor is basically similar to a Servlet Filter, but in
 * contrast to the latter it just allows custom pre-processing with the option
 * of prohibiting the execution of the handler itself, and custom post-processing.
 * Filters are more powerful, for example they allow for exchanging the request
 * and response objects that are handed down the chain. Note that a filter
 * gets configured in web.xml, a HandlerInterceptor in the application context.
 *
 * <p>As a basic guideline, fine-grained handler-related preprocessing tasks are
 * candidates for HandlerInterceptor implementations, especially factored-out
 * common handler code and authorization checks. On the other hand, a Filter
 * is well-suited for request content and view content handling, like multipart
 * forms and GZIP compression. This typically shows when one needs to map the
 * filter to certain content types (e.g. images), or to all requests.
 *
 * @author Juergen Hoeller
 * @since 20.06.2003
 * @see HandlerExecutionChain#getInterceptors
 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter
 * @see org.springframework.web.servlet.handler.AbstractHandlerMapping#setInterceptors
 * @see org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor
 * @see org.springframework.web.servlet.i18n.LocaleChangeInterceptor
 * @see org.springframework.web.servlet.theme.ThemeChangeInterceptor
 * @see javax.servlet.Filter
 */
public interface HandlerInterceptor {

	/**
	 * Intercept the execution of a handler. Called after HandlerMapping determined
	 * an appropriate handler object, but before HandlerAdapter invokes the handler.
	 * <p>DispatcherServlet processes a handler in an execution chain, consisting
	 * of any number of interceptors, with the handler itself at the end.
	 * With this method, each interceptor can decide to abort the execution chain,
	 * typically sending a HTTP error or writing a custom response.
	 * <p><strong>Note:</strong> special considerations apply for asynchronous
	 * request processing. For more details see
	 * {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
	 * <p>The default implementation returns {@code true}.
	 * @param request current HTTP request
	 * @param response current HTTP response
	 * @param handler chosen handler to execute, for type and/or instance evaluation
	 * @return {@code true} if the execution chain should proceed with the
	 * next interceptor or the handler itself. Else, DispatcherServlet assumes
	 * that this interceptor has already dealt with the response itself.
	 * @throws Exception in case of errors
	 */
	default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		return true;
	}

	/**
	 * Intercept the execution of a handler. Called after HandlerAdapter actually
	 * invoked the handler, but before the DispatcherServlet renders the view.
	 * Can expose additional model objects to the view via the given ModelAndView.
	 * <p>DispatcherServlet processes a handler in an execution chain, consisting
	 * of any number of interceptors, with the handler itself at the end.
	 * With this method, each interceptor can post-process an execution,
	 * getting applied in inverse order of the execution chain.
	 * <p><strong>Note:</strong> special considerations apply for asynchronous
	 * request processing. For more details see
	 * {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
	 * <p>The default implementation is empty.
	 * @param request current HTTP request
	 * @param response current HTTP response
	 * @param handler handler (or {@link HandlerMethod}) that started asynchronous
	 * execution, for type and/or instance examination
	 * @param modelAndView the {@code ModelAndView} that the handler returned
	 * (can also be {@code null})
	 * @throws Exception in case of errors
	 */
	default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			@Nullable ModelAndView modelAndView) throws Exception {
	}

	/**
	 * Callback after completion of request processing, that is, after rendering
	 * the view. Will be called on any outcome of handler execution, thus allows
	 * for proper resource cleanup.
	 * <p>Note: Will only be called if this interceptor's {@code preHandle}
	 * method has successfully completed and returned {@code true}!
	 * <p>As with the {@code postHandle} method, the method will be invoked on each
	 * interceptor in the chain in reverse order, so the first interceptor will be
	 * the last to be invoked.
	 * <p><strong>Note:</strong> special considerations apply for asynchronous
	 * request processing. For more details see
	 * {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
	 * <p>The default implementation is empty.
	 * @param request current HTTP request
	 * @param response current HTTP response
	 * @param handler handler (or {@link HandlerMethod}) that started asynchronous
	 * execution, for type and/or instance examination
	 * @param ex exception thrown on handler execution, if any
	 * @throws Exception in case of errors
	 */
	default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
			@Nullable Exception ex) throws Exception {
	}

}

preHandler(HttpServletRequest request, HttpServletResponse response, Object handler) 方法

这个方法是在http请求进来之后处理之前被调用的 返回是 Boolean 类型,返回 false 时,表示直接掐断请求,直接结束了,那么也就不会进入Controller;返回 true 时,会继续进入下一个拦截器同样的方法(preHandler)直到所有的preHandler方法都通过才进入Controller。

postHandler(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) 方法
http请求处理好业务后,从Controller控制器返回后调用,视图解析器之前,也就是在渲染数据返回数据之前被调用。

afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handle, Exception ex) 方法
当对应的拦截器preHandle返回值是 true 时才会在整个请求结束之后执行,视图解析器之后,也可以理解为postHandler后

自定义CustomHandlerInterceptor.java

package boot.example.interceptor.config;



import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomHandlerInterceptor implements HandlerInterceptor{

	/**
	 * Controller逻辑执行之前进行拦截
	 */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle:");
        String uri = request.getRequestURI();
        System.out.println("拦截的uri:"+uri);
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            System.out.println("拦截 Controller:"+ handlerMethod.getBean().getClass().getName());
            System.out.println("拦截方法:"+handlerMethod.getMethod().getName());
        }
        //拦截token,没有token的不允许继续往下执行
        String token = request.getHeader("token");
        if(token == null){
            return false;
        }
        long startTime = System.currentTimeMillis();
        System.out.println("start-time: " + startTime);
        request.setAttribute("startTime", startTime);
        return true;
    }
    
    /**
     * Controller逻辑执行完毕但是视图解析器还为进行解析之前进行拦截
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle:");
        long endTime = System.currentTimeMillis();
        long startTime = (Long) request.getAttribute("startTime");
        System.out.println("post-end-time: " + endTime);
        System.out.println("post-差值ms:" + (endTime - startTime));
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }
    
    /**
     * Controller逻辑和视图解析器执行完毕进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion:");
        long startTime = (Long) request.getAttribute("startTime");
        long endTime = System.currentTimeMillis();
        System.out.println("after-end-time: " + endTime);
        System.out.println("after-差值ms:" + (endTime - startTime));
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}

配置拦截器
bean方式(不推荐)

package boot.example.interceptor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 使用bean的方式
 *
 */
@Configuration
public class InterceptorConfig {

	
    @Bean
    public CustomHandlerInterceptor customHandlerInterceptor(){
        return new CustomHandlerInterceptor();
    }

    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(customHandlerInterceptor())
                        .addPathPatterns("/**")
                        //.excludePathPatterns("/")
                        .excludePathPatterns("/index/**");
            }
        };
    }
    
}

重写方式来配置(推荐)

package boot.example.interceptor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 重写方式来配置,推荐
 *
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public CustomHandlerInterceptor customHandlerInterceptor(){
        return new CustomHandlerInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(customHandlerInterceptor())
                .addPathPatterns("/**")
                //.excludePathPatterns("/")
                .excludePathPatterns("/index/**");
    }
    
}

测试-BootIndexController.java

package boot.example.interceptor.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BootIndexController {

	@RequestMapping("/")
	@ResponseBody
	public String index() {
		return "index";
	}

	@RequestMapping("/index/hello")
	@ResponseBody
	public String indexHello() {
		return "hello world";
	}

	@RequestMapping("/inter/hello")
	@ResponseBody
	public String interHello(){
		return "inter world";
	}

	@RequestMapping("/inter/sleep")
	@ResponseBody
	public String sleepHello() throws InterruptedException {
		// 假装处理2s
		Thread.sleep(2000);
		return "inter world";
	}

}

表示拦截所有的url请求

.addPathPatterns(“/**”)

表示放开拦截的url请求

.excludePathPatterns(“/”)
.excludePathPatterns(“/index/**”)

请求无拦截的情况,直接返回数据,不会经过拦截器
myw

请求有拦截的情况,没有token是访问不到资源的
myw
查看控制台
myw
随意写个token
myw
可以看到拦截通过了 执行了对应的三个方法 在这里有测试的故意延迟
myw
一个应用可能有多个拦截器,有的时候拦截器需要执行的先后顺序,默认的情况下是按照注册的先后顺序
拦截器ONE
CustomOrderOneHandlerInterceptor.java

package boot.example.interceptor.config;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class CustomOrderOneHandlerInterceptor implements HandlerInterceptor{

	/**
	 * Controller逻辑执行之前进行拦截
	 */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("CustomOrderOneHandlerInterceptor: preHandle");
        return true;
    }
    
    /**
     * Controller逻辑执行完毕但是视图解析器还为进行解析之前进行拦截
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("CustomOrderOneHandlerInterceptor: postHandle");
    }
    
    /**
     * Controller逻辑和视图解析器执行完毕进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("CustomOrderOneHandlerInterceptor: afterCompletion");
    }
}

拦截器TWO
CustomOrderTwoHandlerInterceptor.java

package boot.example.interceptor.config;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomOrderTwoHandlerInterceptor implements HandlerInterceptor{

	/**
	 * Controller逻辑执行之前进行拦截
	 */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("CustomOrderTwoHandlerInterceptor: preHandle");
        return true;
    }
    
    /**
     * Controller逻辑执行完毕但是视图解析器还为进行解析之前进行拦截
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("CustomOrderTwoHandlerInterceptor: postHandle");
    }
    
    /**
     * Controller逻辑和视图解析器执行完毕进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("CustomOrderTwoHandlerInterceptor: afterCompletion");
    }
}

拦截器配置
OderInterceptorConfig.java

package boot.example.interceptor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 重写方式来配置,推荐
 *
 */
@Configuration
public class OderInterceptorConfig implements WebMvcConfigurer {

    @Bean
    public CustomOrderOneHandlerInterceptor customOrderOneHandlerInterceptor(){
        return new CustomOrderOneHandlerInterceptor();
    }
    @Bean
    public CustomOrderTwoHandlerInterceptor customOrderTwoHandlerInterceptor(){
        return new CustomOrderTwoHandlerInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(customOrderOneHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index/**");
        registry.addInterceptor(customOrderTwoHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index/**");
    }
    
}

可以看到customOrderOneHandlerInterceptor()在customOrderTwoHandlerInterceptor()之前,启动程序打开访问打开控制台查看打印日志确认
myw
交换顺序可以看到TWO在ONE之前执行
myw
使用order自定义顺序 可以看到值小的比值大的先执行
myw
使用拦截器重定向
当访问

http://localhost:8080

重定向

http://localhost:8080/home

CustomRedirectOneHandlerInterceptor.java

package boot.example.interceptor.config;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class CustomRedirectOneHandlerInterceptor implements HandlerInterceptor{

	/**
	 * Controller逻辑执行之前进行拦截
	 */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("CustomRedirectOneHandlerInterceptor: preHandle");
        System.out.println("CustomRedirectOneHandlerInterceptor Request url: " + request.getRequestURL());
        response.sendRedirect(request.getContextPath()+ "/home");
        return false;
    }
    
    /**
     * Controller逻辑执行完毕但是视图解析器还为进行解析之前进行拦截
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("CustomRedirectOneHandlerInterceptor: postHandle");
    }
    
    /**
     * Controller逻辑和视图解析器执行完毕进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("CustomRedirectOneHandlerInterceptor: afterCompletion");
    }
}


CustomRedirectTwoHandlerInterceptor.java


package boot.example.interceptor.config;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomRedirectTwoHandlerInterceptor implements HandlerInterceptor{

	/**
	 * Controller逻辑执行之前进行拦截
	 */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("CustomRedirectTwoHandlerInterceptor: preHandle");
        System.out.println("CustomRedirectTwoHandlerInterceptor Request url: " + request.getRequestURL());
        return true;
    }
    
    /**
     * Controller逻辑执行完毕但是视图解析器还为进行解析之前进行拦截
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("CustomRedirectTwoHandlerInterceptor: postHandle");
    }
    
    /**
     * Controller逻辑和视图解析器执行完毕进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("CustomRedirectTwoHandlerInterceptor: afterCompletion");
    }
}

BootIndexController.java

package boot.example.interceptor.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BootIndexController {

	@RequestMapping("/")
	@ResponseBody
	public String index() {
		return "/";
	}

	@RequestMapping("/home")
	@ResponseBody
	public String indexHello() {
		return "/home";
	}


}

用postman访问
myw
浏览器输入http://localhost:8080会跳转的
myw
myw

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

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

相关文章

第一部分 随机事件和概率

目录 无放回题目(一次摸多个) 方法&#xff1a; 例1 有放回题目(进行多次&#xff0c;每次情况一致) 方法&#xff1a; 例2 事件的概率 方法&#xff1a; 例3 条件概率 方法&#xff1a; 例4 全概率公式 方法&#xff1a; 例5 贝叶斯公式 方法&#xff1a; 例6 无放回题目(…

方太厨电,在创新科技中看见烟火人间

人类的历史&#xff0c;就是一部创新的历史。科普作者马特里德利在《创新的起源&#xff1a;一部科学技术进步史》写道&#xff1a;能源是所有创新之源。 火的发明和使用&#xff0c;就是一种创新&#xff0c;人类第一次通过控制热量的转换来做功&#xff0c;依靠火来取暖和烹饪…

使用频率分析求周期性

通常很难通过观察时间测量值来表征数据中的振荡行为。频谱分析有助于确定信号是否为周期性信号并测量不同周期。 办公楼内的温度计每半小时测量一次室内温度&#xff0c;持续四个月。加载数据并对其绘图。将温度转换为摄氏度。测量时间以周为单位。因此&#xff0c;采样率为 2 …

高并发处理专题研究 - epoll并发编程[更新中]

文章目录 1 前置知识1.1 Socket编程基础Socket概述Socket通信模型Socket API一个简单的Socket编程实例 1.2 IO多路复用1.3 阻塞原理 2 epoll原理2.1 epoll概述2.2 epoll系统调用epoll_create()epoll_ctl()epoll_wait() 2.3 epoll工作原理 3 示例代码及演示 1 前置知识 1.1 Soc…

Oracle初始化参数修改后,是否需要重启才能生效

可以查看 v$parameter或v$parameter2动态性能视图的ISSYS_MODIFIABLE列。此列指示是否可以使用 ALTER SYSTEM 更改参数以及更改何时生效&#xff1a; IMMEDIATE - 无论用于启动实例的参数文件的类型如何&#xff0c;都可以使用 ALTER SYSTEM 更改参数。 更改立即生效。DEFERRE…

spring核心与思想

spring核心与思想 Spring 是什么&#xff1f;什么是容器&#xff1f;什么是 IoC&#xff1f;传统程序开发传统程序开发的缺陷解决传统开发中的缺陷控制反转式程序开发对⽐总结规律 理解 Spring IoCDI 概念说明 Spring 是什么&#xff1f; Spring 指的是 Spring Framework&…

青龙面板的安装

一、安装docker 首先&#xff0c;需要在服务器上安装docker。 没有服务器的可以使用虚拟机&#xff0c;或申请一台三丰云的免费云服务器体验一下&#xff0c;独立IP地址&#xff0c;送免备案服务&#xff0c;可以满足基本的使用&#xff0c;三丰云上还有免费虚拟主机等其他免费…

【Vue2+3入门到实战】(18)VUE之Vuex状态管理器概述、VueX的安装、核心概念 State状态代码实现 详细讲解

目录 一、[Vuex](https://vuex.vuejs.org/zh/) 概述1.是什么2.使用场景3.优势4.注意&#xff1a; 二、需求: 多组件共享数据1.创建项目2.创建三个组件, 目录如下3.源代码如下 三、vuex 的使用 - 创建仓库1.安装 vuex2.新建 store/index.js 专门存放 vuex3.创建仓库 store/index…

下载大模型,保存阿里云盘

一、解决场景 下载模型或数据集&#xff0c;到国内云GPU平台、阿里云盘&#xff08;便于持久化储存&#xff0c;或者分享朋友&#xff09;。 及时收藏&#xff0c;下次还能找到&#xff01; 二、优势 此方法可以避免大文件下载到本地——占用内存&#xff0c;受到小带宽网络…

SpringBoot定时监听RocketMQ的NameServer

问题分析 自己在测试环境部署了RocketMQ&#xff0c;发现namesrv很容易挂掉&#xff0c;于是就想着监控&#xff0c;挂了就发邮件通知。查看了rocketmq-dashboard项目&#xff0c;发现只能监控Broker&#xff0c;遂放弃这一路径。于是就从报错的日志入手&#xff0c;发现最终可…

vue整理面试题

1. v-if/v-show的区别? v-if"表达式" 当表达式值true&#xff0c;v-if所作用的元素显示 否则隐藏 v-show"表达式" 当表达式值true&#xff0c;v-if所作用的元素显示 否则隐藏 理解&#xff1a; v-if控制元素显示与隐藏&#xff0c;通过js创建dom元素或删除…

用通俗易懂的方式讲解大模型:ChatGLM3-6B 部署指南

最近智谱 AI 对底层大模型又进行了一次升级&#xff0c;ChatGLM3-6B 正式发布&#xff0c;不仅在性能测试和各种测评的数据上有显著提升&#xff0c;还新增了一些新功能&#xff0c;包括工具调用、代码解释器等&#xff0c;最重要的一点是还是保持 6B 的这种低参数量&#xff0…

阿里员工:本月收入489325元,开心过年

阿里员工&#xff1a;本月收入489325元&#xff0c;开心过年 近日&#xff0c;一名阿里员工在社交媒体上爆料自己的本月收入&#xff0c;竟然高达48.9万&#xff0c;真是让人目瞪口呆。 震惊之余&#xff0c;大家都很好奇这么高收入是怎么来的&#xff0c;再仔细看工资单&…

C++初阶——基础知识(内联函数)

目录 1.内联函数 内联函数的示例代码 1.内联函数 是一种 C 中的函数定义方式&#xff0c;它告诉编译器在每个调用点上插入函数体的副本&#xff0c;而不是像普通函数那样在调用时跳转到函数体所在的地址执行。这样可以减少函数调用的开销&#xff0c;提高程序的执行效率。 …

【算法】数论---欧拉函数

什么是欧拉函数&#xff1f; 对于正整数n&#xff0c;欧拉函数是小于或等于n的正整数中与n互质的数的数目&#xff0c;记作φ(n) φ(1)1 当m,n互质时&#xff0c;φ(mn)φ(m)∗φ(n) 一、求一个正整数的欧拉函数---&#xff08;先对它分解质因数&#xff0c;然后套公式&#xf…

子网划分问题(实战超详解)_主机分配地址

文章目录: 子网划分的核心思想 第一步,考虑借几位作为子网号 第二步,确定子网的网络地址 第三步,明确网络地址,广播地址,可用IP地址范围 一些可能出现的疑问 实战 题目一 子网划分的核心思想 网络号不变,借用主机号来产生新的网络 划分前的网络:网络号主机号 划分后的网络:原网…

SpringBoot 一个注解实现数据脱敏

什么是数据脱敏 数据脱敏是指对某些敏感信息&#xff0c;例如姓名、身份证号码、手机号、固定电话、银行卡号、邮箱等个人信息&#xff0c;通过脱敏算法进行数据变形&#xff0c;以保护敏感隐私数据。 数据脱敏通常涉及以下几种主要方法&#xff1a; 替换&#xff1a; 将原始…

【量化】蜘蛛网策略复现

文章目录 蜘蛛网策略研报概述持仓数据整理三大商品交易所的数据统一筛选共有会员清洗数据计算研报要求数据全部代码 策略结果分析无参数策略有参数策略正做反做 MSD技术指标化 蜘蛛网策略 策略来自《东方证券-股指期货趋势交易之蜘蛛网策略——从成交持仓表中捕捉知情投资者行为…

Blender:从新手到专家的全方位指南

Blender&#xff0c;这款强大的开源3D建模和渲染软件&#xff0c;已经成为了CG行业的标准工具之一。它不仅拥有丰富的教程资源&#xff0c;而且还在不断发展和完善中。尽管Blender的教程主要集中在国外网站和YouTube上&#xff0c;但其全面的功能和易用性使它成为许多人的首选工…

电子邮件地址填写指南:格式与常见问题解答

一个专业的电子邮件地址是一个你只用于工作目的的通信帐户。当你给收件人发送电子邮件时&#xff0c;这是他们最先看到的细节之一。无论你的职位或行业如何&#xff0c;拥有一个专业的电子邮件地址都可以提高你和所在公司的可信度。 在本文中我们解释了专业的电子邮件地址是什么…