SpringBoot注册Servlet、Filter、Listener、Interceptor四大组件

SpringBoot中注册四大组件

文章目录

  • SpringBoot中注册四大组件
  • 1. Servlet注册
    • 1. 基于配置类方式使用Servlet使用Servlet方式
    • 2. 基于纯注解方式配置Servlet
  • 2. Filter(过滤器)注册
    • 1. 以配置类方式注册Filter
    • 2. 以纯注解方式注册Filter
    • 3. 以注解的方式注册Filter执行顺序不生效问题
  • 3. Listener(监听器)注册
    • 1. `@Component`注解
    • 2. `@EventListener`注册监听
    • 3. 主启动配置监听
  • 4. Interceptor(拦截器)注册
  • 5. 执行顺序

SpringBoot版本:2.2.5 GA 版

GA=General Availability,字面意思是 一般或正常可用性。

代表的是官方正式发布的版本,推荐可广泛使用的版本,国外有的软件用GA来表示RELEASE版本。 RELEASE表示正式发布版

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

1. Servlet注册

有两种使用方式

1.基于配置类方式使用Servlet

2.基于纯注解方式使用Servlet

1. 基于配置类方式使用Servlet使用Servlet方式

  1. 自定义一个MyServlet类,让其继承HttpServlet类

  2. 在配置类中使用ServletRegistrationBean类注册自定义MyServlet类

  3. 设置相关属性并访问

  1. MyServlet
package com.yuan.demo.servlet;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;public class MyServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {String requestURI = req.getRequestURI();System.out.println("requestURI" + requestURI);System.out.println("req.getRequestURL()" + req.getRequestURL());resp.getWriter().write("Hello,Servlet!!!");}
}

配置类

package com.yuan.demo.config;import com.yuan.demo.filter.MyFilter;
import com.yuan.demo.listener.MyListener;
import com.yuan.demo.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/**** 注册自定义的Servlet*/
@Configuration
public class RegisterServerConfig {/*** 注册自定义Servlet* @return*/@Beanpublic ServletRegistrationBean myServlet(){ServletRegistrationBean<MyServlet> registrationBean = new ServletRegistrationBean<>(new MyServlet());registrationBean.addUrlMappings("/hello","/myServlet");return registrationBean;}/**** 注册自定义Filter* @return*/@Beanpublic FilterRegistrationBean myFilter(){FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();filterRegistrationBean.setFilter(new MyFilter());//设置自定义拦截器filterRegistrationBean.addUrlPatterns("/hello","/myServlet");//设置要拦截的请求return filterRegistrationBean;}/*** 注册自定义Listener* @return*/@Beanpublic ServletListenerRegistrationBean myListener(){ServletListenerRegistrationBean<MyListener> registrationBean = new ServletListenerRegistrationBean<>(new MyListener());return registrationBean;}
}

2. 基于纯注解方式配置Servlet

  1. 写一个继承HttpServlet的类,并在其上面加上**@WebServlet**注解
  2. 在SpringBoot的主启动类上加上**@ServletComponentScan**注解
  1. MyServletOne.java
package com.yuan.servlet;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@WebServlet(value = {"/aa","/bb"}) //配置请求路径,其他参数看源码
public class MyServletOne extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("req.getRequestURI()====>"+req.getRequestURI());resp.getWriter().write("Hello,MyServletOne!!!");}
}
  1. SpringBoot主启动如下:
package com.yuan;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@ServletComponentScan
@SpringBootApplication
public class MyServletApplication {public static void main(String[] args) {SpringApplication.run(MyServletApplication.class,args);}
}
  1. 打开浏览器输入http://localhost:8080/aa,输出结果如下:
Hello,MyServletOne!!!

2. Filter(过滤器)注册

1. 以配置类方式注册Filter

  1. 自定义一个Filter类(如:MyFilter.java)让其实现Filter接口并实现相关方法
  2. 在配置类中注册 FilterRegistrationBean,设置过滤的URL等
  3. 编写测试案例进行过滤器测试

2. 以纯注解方式注册Filter

  1. 在在定义的Filter类中加入**@WebFilter**注解,并设置filterName及过滤的URL
  2. 在主启动类上加入 @ServletComponentScan注解
  3. 启动服务器进行测试

3. 以注解的方式注册Filter执行顺序不生效问题

  1. 问题描述,使用**@WebFilter方式注入filter后,用@Order**注解指定filter的执行顺序则不起作用

  2. 原因分析:

阅读源码发现:重点在ServletComponentHandler 处理带有注解WebFilter的类;handle方法中处理的attributes是@WebFilter的属性,因为@WebFilter本身是没有Order属性,所以构建的Filter将是默认的Order值,而上面源码可得知,类名可决定注册Filter的顺序(即Filter过滤顺序,因为此处只能注册默认的Order值)

  1. 解决方法:
    1. 以自定义的Filter名称(属性filterName=“myFilter”)来改变其执行顺序
    1. 使用配置类的方式,直接 对象.setOrder(2)来改变其顺序,order值越小优先级越高
//根据MyFilter会在MyFilterOne执行后再执行
@WebFilter(filterName = "bmyFilter",urlPatterns = {"/*","/one/*"})
public class MyFilter implements Filter {.......
}
//MyFilterOne会被先执行
@WebFilter(filterName = "amyFilter",urlPatterns = {"/*","/one/*"})
public class MyFilterOne implements Filter {...}

注:SpringBoot自带初始化的Filter

Spring Boot 自带的4中Filter,主要为了了解其过滤顺序,且与自定义Filter的执行顺序。(由Order值从小到大的顺序),由Filter类名来实现自定义Filter顺序,因Order为默认值,所以自带的4种Filter都会比自定义的Filter先执行。

 org.springframework.boot.web.servlet.FilterRegistrationBean 258 - Mapping filter: 'characterEncodingFilter' to: [/*]org.springframework.boot.web.servlet.FilterRegistrationBean 258 - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]org.springframework.boot.web.servlet.FilterRegistrationBean 258 - Mapping filter: 'httpPutFormContentFilter' to: [/*]org.springframework.boot.web.servlet.FilterRegistrationBean 258 - Mapping filter: 'requestContextFilter' to: [/*]
  • CharacterEncodingFilter :编码过滤器
/** Copyright 2012-2019 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**      https://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.boot.web.servlet.filter;import org.springframework.core.Ordered;
import org.springframework.web.filter.CharacterEncodingFilter;/*** {@link CharacterEncodingFilter} that also implements {@link Ordered}.** @author Phillip Webb* @since 2.0.0*/
public class OrderedCharacterEncodingFilter extends CharacterEncodingFilter implements OrderedFilter {private int order = Ordered.HIGHEST_PRECEDENCE; //HIGHEST_PRECEDENCE = -2147483648;@Overridepublic int getOrder() {return this.order;}/*** Set the order for this filter.* @param order the order to set*/public void setOrder(int order) {this.order = order;}
}
  • HiddenHttpMethodFilter :处理隐藏的PUT,DELETE等请求方法
/** Copyright 2012-2019 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**      https://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.boot.web.reactive.filter;import org.springframework.core.Ordered;
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;/*** {@link HiddenHttpMethodFilter} that also implements {@link Ordered}.** @author Artsiom Yudovin* @since 2.0.5*/
public class OrderedHiddenHttpMethodFilter extends HiddenHttpMethodFilter implements OrderedWebFilter {/*** The default order is high to ensure the filter is applied before Spring Security.*/public static final int DEFAULT_ORDER = REQUEST_WRAPPER_FILTER_MAX_ORDER - 10000;private int order = DEFAULT_ORDER;@Overridepublic int getOrder() {return this.order;}/*** Set the order for this filter.* @param order the order to set*/public void setOrder(int order) {this.order = order;}}
  • HttpPutFormContentFilter :处理PUT表单请求
/** Copyright 2002-2018 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**      https://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.filter;import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;/*** {@link javax.servlet.Filter} that makes form encoded data available through* the {@code ServletRequest.getParameter*()} family of methods during HTTP PUT* or PATCH requests.** <p>The Servlet spec requires form data to be available for HTTP POST but* not for HTTP PUT or PATCH requests. This filter intercepts HTTP PUT and PATCH* requests where content type is {@code 'application/x-www-form-urlencoded'},* reads form encoded content from the body of the request, and wraps the ServletRequest* in order to make the form data available as request parameters just like* it is for HTTP POST requests.** @author Rossen Stoyanchev* @since 3.1* @deprecated as of 5.1 in favor of {@link FormContentFilter} which is the same* but also handles DELETE.*/
@Deprecated
public class HttpPutFormContentFilter extends OncePerRequestFilter {private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();/*** Set the converter to use for parsing form content.* <p>By default this is an instance of {@link AllEncompassingFormHttpMessageConverter}.*/public void setFormConverter(FormHttpMessageConverter converter) {Assert.notNull(converter, "FormHttpMessageConverter is required.");this.formConverter = converter;}public FormHttpMessageConverter getFormConverter() {return this.formConverter;}/*** The default character set to use for reading form data.* This is a shortcut for:<br>* {@code getFormConverter.setCharset(charset)}.*/public void setCharset(Charset charset) {this.formConverter.setCharset(charset);}@Overrideprotected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,FilterChain filterChain) throws ServletException, IOException {if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {@Overridepublic InputStream getBody() throws IOException {return request.getInputStream();}};MultiValueMap<String, String> formParameters = this.formConverter.read(null, inputMessage);if (!formParameters.isEmpty()) {HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);filterChain.doFilter(wrapper, response);return;}}filterChain.doFilter(request, response);}private boolean isFormContentType(HttpServletRequest request) {String contentType = request.getContentType();if (contentType != null) {try {MediaType mediaType = MediaType.parseMediaType(contentType);return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));}catch (IllegalArgumentException ex) {return false;}}else {return false;}}private static class HttpPutFormContentRequestWrapper extends HttpServletRequestWrapper {private MultiValueMap<String, String> formParameters;public HttpPutFormContentRequestWrapper(HttpServletRequest request, MultiValueMap<String, String> parameters) {super(request);this.formParameters = parameters;}@Override@Nullablepublic String getParameter(String name) {String queryStringValue = super.getParameter(name);String formValue = this.formParameters.getFirst(name);return (queryStringValue != null ? queryStringValue : formValue);}@Overridepublic Map<String, String[]> getParameterMap() {Map<String, String[]> result = new LinkedHashMap<>();Enumeration<String> names = getParameterNames();while (names.hasMoreElements()) {String name = names.nextElement();result.put(name, getParameterValues(name));}return result;}@Overridepublic Enumeration<String> getParameterNames() {Set<String> names = new LinkedHashSet<>();names.addAll(Collections.list(super.getParameterNames()));names.addAll(this.formParameters.keySet());return Collections.enumeration(names);}@Override@Nullablepublic String[] getParameterValues(String name) {String[] parameterValues = super.getParameterValues(name);List<String> formParam = this.formParameters.get(name);if (formParam == null) {return parameterValues;}if (parameterValues == null || getQueryString() == null) {return StringUtils.toStringArray(formParam);}else {List<String> result = new ArrayList<>(parameterValues.length + formParam.size());result.addAll(Arrays.asList(parameterValues));result.addAll(formParam);return StringUtils.toStringArray(result);}}}}
  • RequestContextFilter :设置请求的上下文环境
/** Copyright 2002-2015 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**      https://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.filter;import java.io.IOException;import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;/*** Servlet Filter that exposes the request to the current thread,* through both {@link org.springframework.context.i18n.LocaleContextHolder} and* {@link RequestContextHolder}. To be registered as filter in {@code web.xml}.** <p>Alternatively, Spring's {@link org.springframework.web.context.request.RequestContextListener}* and Spring's {@link org.springframework.web.servlet.DispatcherServlet} also expose* the same request context to the current thread.** <p>This filter is mainly for use with third-party servlets, e.g. the JSF FacesServlet.* Within Spring's own web support, DispatcherServlet's processing is perfectly sufficient.** @author Juergen Hoeller* @author Rod Johnson* @author Rossen Stoyanchev* @since 2.0* @see org.springframework.context.i18n.LocaleContextHolder* @see org.springframework.web.context.request.RequestContextHolder* @see org.springframework.web.context.request.RequestContextListener* @see org.springframework.web.servlet.DispatcherServlet*/
public class RequestContextFilter extends OncePerRequestFilter {private boolean threadContextInheritable = false;/*** Set whether to expose the LocaleContext and RequestAttributes as inheritable* for child threads (using an {@link java.lang.InheritableThreadLocal}).* <p>Default is "false", to avoid side effects on spawned background threads.* Switch this to "true" to enable inheritance for custom child threads which* are spawned during request processing and only used for this request* (that is, ending after their initial task, without reuse of the thread).* <p><b>WARNING:</b> Do not use inheritance for child threads if you are* accessing a thread pool which is configured to potentially add new threads* on demand (e.g. a JDK {@link java.util.concurrent.ThreadPoolExecutor}),* since this will expose the inherited context to such a pooled thread.*/public void setThreadContextInheritable(boolean threadContextInheritable) {this.threadContextInheritable = threadContextInheritable;}/*** Returns "false" so that the filter may set up the request context in each* asynchronously dispatched thread.*/@Overrideprotected boolean shouldNotFilterAsyncDispatch() {return false;}/*** Returns "false" so that the filter may set up the request context in an* error dispatch.*/@Overrideprotected boolean shouldNotFilterErrorDispatch() {return false;}@Overrideprotected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)throws ServletException, IOException {ServletRequestAttributes attributes = new ServletRequestAttributes(request, response);initContextHolders(request, attributes);try {filterChain.doFilter(request, response);}finally {resetContextHolders();if (logger.isTraceEnabled()) {logger.trace("Cleared thread-bound request context: " + request);}attributes.requestCompleted();}}private void initContextHolders(HttpServletRequest request, ServletRequestAttributes requestAttributes) {LocaleContextHolder.setLocale(request.getLocale(), this.threadContextInheritable);RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);if (logger.isTraceEnabled()) {logger.trace("Bound request context to thread: " + request);}}private void resetContextHolders() {LocaleContextHolder.resetLocaleContext();RequestContextHolder.resetRequestAttributes();}
}

3. Listener(监听器)注册

1. @Component注解

  1. 编写自定义监听类如RegListenerTwo实现ApplicationListener接口
  2. 在自定义监听类上面标注 @Component注解
package com.yuan.regcomponent;import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;@Component
public class RegListenerTwo implements ApplicationListener {@Overridepublic void onApplicationEvent(ApplicationEvent event) {System.out.println("RegListenerTwo====执行了");}
}

2. @EventListener注册监听

  1. 编写自定义监听类如RegListenerTwo实现ApplicationListener接口
  2. 在自定义监听类上面标注 @Component注解
  3. 在自定义类中编写一个监听方法,并在方法上标注@EventListener注解
package com.yuan.regcomponent;import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;@Component
public class RegListenerThree {@EventListenerpublic void onApplicationEvent(ApplicationEvent event) {System.out.println("RegListenerThree====执行了");}
}

3. 主启动配置监听

  1. 编写自定义监听类如RegListenerOne实现ApplicationListener接口
  2. 在主启动类上面标注@ServletComponentScan
  3. 将自定义的监听类加入到SpringApplication的监听中
  1. 编写监听类
package com.yuan.regcomponent;import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;public class RegListenerOne implements ApplicationListener {@Overridepublic void onApplicationEvent(ApplicationEvent event) {System.out.println("RegListenerOne====执行了");}
}
  1. 直接启动类开启注解并添加自定义监听
package com.yuan;import com.yuan.regcomponent.RegListenerOne;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication
@ServletComponentScan
public class YuanBootDiskfileApplication {public static void main(String[] args) {//SpringApplication.run(YuanBootDiskfileApplication.class, args);SpringApplication springApplication = new SpringApplication(YuanBootDiskfileApplication.class);springApplication.addListeners(new RegListenerOne());//添加自定义监听类springApplication.run(args);}}

4. Interceptor(拦截器)注册

  1. 自定义拦截器
package com.yuan.demo.interceptor;import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** 自定义拦截器*/
public class MyInterceptor implements HandlerInterceptor {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {System.out.println("MyInterceptor拦截器。。。。处理前");return true;}@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {StringBuffer requestURL = request.getRequestURL();System.out.println("MyInterceptor拦截器拦截了请求:"+requestURL);}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {System.out.println("MyInterceptor拦截器。。。。处理后");}
}
  1. 注册拦截器
package com.yuan.demo.config;import com.yuan.demo.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {@Overridepublic void addInterceptors(InterceptorRegistry registry) {InterceptorRegistration interceptor = registry.addInterceptor(new MyInterceptor());interceptor.addPathPatterns("/hello","/test");//拦截的urlinterceptor.excludePathPatterns("/login");//排除拦截的urlinterceptor.order(1);//拦截顺序}
}

5. 执行顺序

注意: 监听器 、 过滤器、 拦截器 执行优先顺序如下

监听器 > 过滤器 > 拦截器

  1. 同时配置了Servlet,过滤器,拦截器,优先顺序如下

Servlet>Filter>Interceptor

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

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

相关文章

记一次多平台免杀PHP木马的制作过程

注意&#xff1a;本文转载自本作者稀土掘金博客 博客地址&#xff1a; 御坂19008号 的个人主页 - 动态 - 掘金 文章目录 前言声明绕过情况使用方法运行环境绕过点介绍技术原理讲解变量传值覆盖模块代码执行阻断模块InazumaPuzzle程序锁定器PerlinNoise危险函数生成与执行类构造…

基于springboot+vue考编论坛

摘要 近年来&#xff0c;随着互联网的迅猛发展&#xff0c;编程论坛成为程序员们交流学术、分享经验的重要平台之一。为了满足广大程序员的需求&#xff0c;本文基于Spring Boot和Vue框架&#xff0c;设计并实现了一个功能强大的编程论坛。首先&#xff0c;我们选择Spring Boot…

Laya3.0 相机使用

摄像机&#xff0c;是3D场景里边最经常使用的对象了。 官方文档&#xff1a;点击这里学习 1.投影 Projection 透视&#xff1a; 模拟人眼的视觉效果&#xff0c;近大远小。模拟物理世界的规律&#xff0c;将眼睛或相机抽象成一个点&#xff0c;此时视锥体内的物体投影到视平…

ChatGPT时代对大数据应用的展望

前言&#xff1a; 2022年底&#xff0c;科技圈有个爆炸性新闻&#xff0c;ChatGPT的诞生&#xff0c;引发了世界范围内的震惊&#xff1b;人工智能在与人交流上有了划时代的技术突破&#xff0c;可以和人深入的理解交流&#xff0c;让许多公司和领域对这项技术有了更多遐想。对…

HAOI2008 排名系统

P4291 [HAOI2008] 排名系统 题目大意 有一个排名系统和 n n n次操作&#xff0c;操作分为以下三种&#xff1a; Name Score&#xff1a;上传一条新的得分记录?Name&#xff1a;查询某个玩家的当前排名?Index&#xff1a;返回某个区段内的排名记录 当某个玩家上传自己最新…

开源项目盘点-学习类

1&#xff0c;freeCodeCamp 地址&#xff1a;https://github.com/freeCodeCamp/freeCodeCamp 描述&#xff1a;一个程序员学习网站&#xff0c;里面有全栈开发、机器学习的相关知识&#xff0c;是完全免费的&#xff0c;该网站有上千道编码挑战题来帮助你来练习你的技能。 提…

ajax的优缺点?

AJAX&#xff08;Asynchronous JavaScript and XML&#xff09;是一种使用异步请求来更新网页的技术&#xff0c;它可以在不重新加载整个页面的情况下&#xff0c;通过与服务器交换数据来更新部分网页内容。以下是AJAX的主要优点和缺点&#xff1a; 优点&#xff1a; 提升用户…

Linux———groupadd,groupdel,groupmod命令联合总结(狠狠爱住)

目录 groupadd 命令 groupadd 命令基本语法&#xff1a; groupadd 命令常用选项&#xff1a; 下面是一些示例来演示如何使用 groupadd 命令&#xff1a; groupdel 命令&#xff1a; groupdel 命令基本语法&#xff1a; groupdel 命令常用的选项有&#xff1a; 下面是一…

样本处理之SMOTE算法

1. 少数类别过采样技术SMOTE简介 Synthetic Minority Oversampling Technique&#xff0c;是一种用于合成少数类样本的过采样技术&#xff0c;通过对训练集中的正例进行插值来产生额外的正例。 基本思想&#xff1a; 对少数类样本进行分析&#xff0c;然后在现有少数类样本之间…

AI对比:ChatGPT与文心一言的异同与未来

文章目录 &#x1f4d1;前言一、ChatGPT和文心一言概述1.1 ChatGPT1.2 文心一言 二、ChatGPT和文心一言比较2.1 训练数据与知识储备2.2 语义理解与生成能力2.2 应用场景与商业化探索 三、未来展望3.1 模型规模与参数数量不断增加3.2 多模态交互成为主流3.3 知识图谱与大模型的结…

大数据平台的硬件规划、网络调优、架构设计、节点规划

1.大数据平台硬件选型 要对Hadoop大数据平台进行硬件选型,首先需要了解Hadoop的运行架构以及每个角色的功能。在一个典型的Hadoop架构中,通常有5个角色,分别是NameNode、Standby NameNode、ResourceManager、NodeManager、DataNode以及外围机。 其中 NameNode 负责协调集群…

每周AI新闻(2024年第3周)Meta研发Llama 3 | 苹果Vision Pro预售 | 智谱AI发布GLM-4

我是陌小北&#xff0c;一个正在研究硅基生命的、有趣儿的碳基生命。每周日20:00&#xff0c;准时解读每周AI大事件。 大厂动向 【1】Meta研发Llama 3&#xff0c;构建开源AGI Meta公司CEO马克扎克伯格&#xff08;Mark Zuckerberg&#xff09;宣布公司将对两个关键AI研究部…

客户需求,就是项目管理中最难管的事情

对于需求控制和管理 个人的观点是&#xff1a;首先要向客户传递开发流程&#xff0c;第二必须制作原型&#xff0c;需求确认时确认的是原型&#xff0c;而不是需求文档&#xff0c;第三&#xff0c;开发阶段要快速迭代&#xff0c;与客户互动。管人方面我想对于项目经理来讲&am…

【51单片机】

0、前言 参考&#xff1a;普中 51 单片机开发攻略 第14章 1、硬件 ULN2003 芯片 2、软件 mian.c #include <reg52.h> #include <intrins.h> #include "delayms.h"typedef unsigned char u8; typedef unsigned int u16;sbit DC_MotorP1^0;void DC_Mo…

Ubuntu 使用 git 能够 clone 但不能 push 的参考解决方法

写在前面 自己的测试环境&#xff1a;Ubuntu20.04 下面的操作都是和 git 有关&#xff0c;所以针对不同的操作系统&#xff08;比如 Windows&#xff09;也是一样的。 一、问题描述 在此之前使用git执行 git push origin master 的命令时&#xff0c;能够正常执行&#xff0…

【计算机网络】【Python】【练习题】【新加坡南洋理工大学】【Computer Control Network】

一、题目描述 该题目描述一个网络中数据包交换&#xff08;Packet Switching&#xff09;的例子。题目如下&#xff1a; 二、问题解答&#xff08;使用Python&#xff09; Q1&#xff1a;如何求出0.0004这个值&#xff1f; &#xff08;1&#xff09;、公式推导过程&#xf…

数据库防水坝是什么?有什么作用?有哪些优势?

数据库是公司重要IT资产&#xff0c;是公司数据存储、数据整合、数据备份等重要载体。所以保障数据库安全至关重要。目前保障数据库安全产品较多&#xff0c;例如堡垒机、防火墙、数据库防水坝等等。今天我们就先来简单了解一下数据库防水坝是什么&#xff1f;有什么作用&#…

CMU15-445-Spring-2023-分布式DBMS初探(lec21-24)

Lecture #21_ Introduction to Distributed Databases Distributed DBMSs 分布式 DBMS 将单个逻辑数据库划分为多个物理资源。应用程序&#xff08;通常&#xff09;并不知道数据被分割在不同的硬件上。系统依靠单节点 DBMS 的技术和算法来支持分布式环境中的事务处理和查询执…

Scikit-Learn 中级教程——特征缩放

Python Scikit-Learn 中级教程&#xff1a;特征缩放 在机器学习中&#xff0c;特征缩放是一个重要的预处理步骤。它用于调整数据中特征的范围&#xff0c;以便模型能够更好地收敛和表现。在本篇博客中&#xff0c;我们将深入介绍 Scikit-Learn 中的特征缩放方法&#xff0c;并…

DAG最小路径点覆盖,最小路径可重复覆盖,详解

文章目录 前言有向无环图的最小路径点覆盖概念拆点二分图定理**证明** 最小路径可重复覆盖解决策略代码实现 OJ练习 前言 关于二分图&#xff1a;二分图及染色法判定 关于二分图最大匹配&#xff1a;二分图最大匹配——匈牙利算法详解 关于二分图带权最大完备匹配&#xff1…