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

SpringBoot错误处理机制解析

SpringBoot错误处理----源码解析

文章目录

    • 1、默认机制
    • 2、使用@ExceptionHandler标识一个方法,处理用@Controller标注的该类发生的指定错误
      • 1).局部错误处理部分源码
      • 2).测试
    • 3、 创建一个全局错误处理类集中处理错误,使用==@ControllerAdvice==注解标注
      • 1).全局错误处理部分源码
      • 3).测试
    • 4、SpringMVC错误处理未能处理(上述处理不存在)
        • 1、SpringBoot中自动配置的错误处理机制,基于`ErrorMvcAutoConfiguration`自动配置实现
        • 2、` BasicErrorController`组件
        • 规则如下:
    • 5、自定义错误响应
    • 6、测试
        • 1、在项目的resources/templates/目录下创建一个error文件夹,放入4xx.html、5xx.html
        • 2、在项目的resources/templates/error文件夹中,再放入404.html、500.html
        • 3、浏览器先后测试上述情况

1、默认机制

SpringBoot错误处理的自动配置都在ErrorMvcAutoConfiguration中,两大核心机制:

  • 1.SpringBoot会自适应处理错误,响应页面或JSON数据

  • 2.SpringMVC的错误处理机制依然保留,MVC处理不了,才会交给SpringBoot进行处理。
    在这里插入图片描述(图片来自尚硅谷)

2、使用@ExceptionHandler标识一个方法,处理用@Controller标注的该类发生的指定错误

(默认只能处理这个类的该指定错误)

// @ExceptionHandler源码
@Target({ElementType.METHOD})     // 指定了该注解仅能用于方法
@Retention(RetentionPolicy.RUNTIME)   //指定了注解会在运行时保留,这允许通过反射在运行时获取对注解的访问
@Documented      //注解应该被包含在生成的 JavaDoc 文档中
@Reflective({ExceptionHandlerReflectiveProcessor.class}) 
public @interface ExceptionHandler {Class<? extends Throwable>[] value() default {};       //它定义了一个名为 value 的属性,其类型是一个 Class 数组,这个数组的元素必须是 Throwable 类或其子类。通过使用这个注解时,可以为 value 属性提供一个 Throwable 类型的数组
}

1).局部错误处理部分源码

@Controller         //适配服务端渲染    前后不分离模式开始
public class WelcomeController {//来到首页@GetMapping("/")public String index(){int i=10/0;    //制造错误return "index";}@ResponseBody     //返回的字符串应该直接作为 HTTP 响应体的内容,而不是作为视图名称解析。通常用于返回 JSON 或纯文本等非HTML内容@ExceptionHandler(Exception.class)   //传递到value数组中public String handleException(Exception e){return "Ohho~~~,原因:"+e.getMessage();}}

2).测试

  • 1.启动项目,浏览器访问http://localhost:8080/

  • 2.测试结果(成功处理错误)
    在这里插入图片描述

3、 创建一个全局错误处理类集中处理错误,使用==@ControllerAdvice==注解标注

(这个类是集中处理所有@Controller 发生的错误)

//@ControllerAdvice源码
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component       //标记类为一个 Spring 组件
public @interface ControllerAdvice {@AliasFor(annotation = Component.class,attribute = "value")String name() default "";@AliasFor("basePackages")String[] value() default {};@AliasFor("value")String[] basePackages() default {};Class<?>[] basePackageClasses() default {};Class<?>[] assignableTypes() default {};Class<? extends Annotation>[] annotations() default {};
}

1).全局错误处理部分源码

@ControllerAdvice        //这个类是集中处理所有@Controller发生的错误
public class GlobalExceptionHandler {@ResponseBody@ExceptionHandler(Exception.class)public String handleException(Exception e){return "Ohho~~~统一处理所有错误,原因:"+e.getMessage();}
}

###2).再创建一个类,使用@Controller注解标注

@Controller
public class HelloController {@GetMapping("/haha")public String haha(){int i = 10/0;        //制造错误return "index";}
}

3).测试

  • 1.启动项目,浏览器访问http://localhost:8080/
  • 2.测试结果(成功处理错误)就近原则,执行的是@Controller类中标注了@ExceptionHandler方法的处理
    在这里插入图片描述
  • 3.浏览器访问http://localhost:8080/haha全局错误处理类进行处理
    在这里插入图片描述

4、SpringMVC错误处理未能处理(上述处理不存在)

第一阶段的处理未解决,错误转发到/error,执行后续处理(图中第一阶段失效,第二阶段处理),以下测试过程中,注释掉上文中的全局和局部处理代码

1、SpringBoot中自动配置的错误处理机制,基于ErrorMvcAutoConfiguration自动配置实现

ErrorMvcAutoConfiguration自动装配类中,SpringBoot在底层写好一个 ==BasicErrorController==的组件,专门处理/error这个请求,部分源码如下:

@AutoConfiguration(before = WebMvcAutoConfiguration.class) //指定了该自动配置类在 WebMvcAutoConfiguration 之前进行配置
@ConditionalOnWebApplication(type = Type.SERVLET)    //只有在当前应用是一个 Servlet Web 应用时,这个自动配置才会生效
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })   //只有当类路径中存在 Servlet 和 DispatcherServlet 时,这个自动配置才会生效
@EnableConfigurationProperties({ ServerProperties.class, WebMvcProperties.class }) //启用指定类的配置属性绑定
public class ErrorMvcAutoConfiguration {private final ServerProperties serverProperties; //注入了 ServerProperties 实例。这样的构造方法注入是为了获取应用程序的服务器配置public ErrorMvcAutoConfiguration(ServerProperties serverProperties) {this.serverProperties = serverProperties;  //注入 ServerProperties 实例}//容器中不存在 ErrorAttributes 类型的 Bean 时,才会创建并注册当前方法所返回的 Bean@Bean@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)public DefaultErrorAttributes errorAttributes() {return new DefaultErrorAttributes();}//在容器中不存在 ErrorController 类型的 Bean 时,才会创建并注册当前方法所返回的 Bean@Bean@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)public BasicErrorController basicErrorController(ErrorAttributes errorAttributes,ObjectProvider<ErrorViewResolver> errorViewResolvers) {return new BasicErrorController(errorAttributes, this.serverProperties.getError(),errorViewResolvers.orderedStream().toList());}...
}
2、 BasicErrorController组件

SpringBoot中默认的server.error.path=/error,即该类就是处理/error请求的,根据不同类型的请求,如果产生 HTML 内容的请求,匹配public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) 这个方法;否则其他请求类型,匹配public ResponseEntity<Map<String, Object>> error(HttpServletRequest request)方法。分别进行处理。(只会匹配其中一个,Spring MVC会尝试匹配与请求路径最匹配的RequestMapping)

  • 1.部分源码:
@Controller
@RequestMapping("${server.error.path:${error.path:/error}}")
public class BasicErrorController extends AbstractErrorController {private final ErrorProperties errorProperties;/*** Create a new {@link BasicErrorController} instance.* @param errorAttributes the error attributes* @param errorProperties configuration properties*/public BasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) {this(errorAttributes, errorProperties, Collections.emptyList());}/*** Create a new {@link BasicErrorController} instance.* @param errorAttributes the error attributes* @param errorProperties configuration properties* @param errorViewResolvers error view resolvers*/public BasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties,List<ErrorViewResolver> errorViewResolvers) {super(errorAttributes, errorViewResolvers);Assert.notNull(errorProperties, "ErrorProperties must not be null");this.errorProperties = errorProperties;}@RequestMapping(produces = MediaType.TEXT_HTML_VALUE)   //请求类型为HTML 文本public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {HttpStatus status = getStatus(request);Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.TEXT_HTML)));response.setStatus(status.value());ModelAndView modelAndView = resolveErrorView(request, response, status, model);return (modelAndView != null) ? modelAndView : new ModelAndView("error", model);}@RequestMappingpublic ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {HttpStatus status = getStatus(request);if (status == HttpStatus.NO_CONTENT) {return new ResponseEntity<>(status);}Map<String, Object> body = getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.ALL));return new ResponseEntity<>(body, status);}...
}
  • 2.匹配成功之后,错误页面解析的核心代码

    //1、解析错误的自定义视图地址
    ModelAndView modelAndView = resolveErrorView(request, response, status, model);
    //2、如果解析不到错误页面的地址,默认的错误页就是 error
    return (modelAndView != null) ? modelAndView : new ModelAndView("error", model);
    
  • 3.在ErrorMvcAutoConfiguration自动装配类中,SpringBoot在底层写好一个 ==DefaultErrorViewResolver==的组件,注入到了容器中

    	@Configuration(proxyBeanMethods = false)@EnableConfigurationProperties({ WebProperties.class, WebMvcProperties.class })static class DefaultErrorViewResolverConfiguration {private final ApplicationContext applicationContext;private final Resources resources;DefaultErrorViewResolverConfiguration(ApplicationContext applicationContext, WebProperties webProperties) {this.applicationContext = applicationContext;this.resources = webProperties.getResources();}@Bean@ConditionalOnBean(DispatcherServlet.class)@ConditionalOnMissingBean(ErrorViewResolver.class)DefaultErrorViewResolver conventionErrorViewResolver() {return new DefaultErrorViewResolver(this.applicationContext, this.resources);}}
    
  • 4.在DefaultErrorViewResolver中定义了错误页的默认规则,功能如下:

    • 如果在类路径下,查看是否存在 error/错误码 的页面,存在就返回该视图;
    • 否则,去4个CLASSPATH_RESOURCE_LOCATIONS路径下,查看是否写了 error/错误码.html 的页面,存在则返回该视图;
    • 都不存在,则modelAndView=null;则判断是否有 error/4xx 或者 error/5xx 的页面,存在则返回该视图
    • 否则,去4个CLASSPATH_RESOURCE_LOCATIONS路径下,查看是否写了 error/4xx.html 或者 error/5xx.html 的页面,存在则返回该视图;
    public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {...private static final Map<Series, String> SERIES_VIEWS;static {Map<Series, String> views = new EnumMap<>(Series.class);views.put(Series.CLIENT_ERROR, "4xx");views.put(Series.SERVER_ERROR, "5xx");SERIES_VIEWS = Collections.unmodifiableMap(views);}// 查看是否存在 error/错误码 的页面,存在就返回该视图// 不存在,则判断是否有  error/4xx  或者  error/5xx  的页面,存在则返回该视图@Overridepublic ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {ModelAndView modelAndView = resolve(String.valueOf(status.value()), model);if (modelAndView == null && SERIES_VIEWS.containsKey(status.series())) {modelAndView = resolve(SERIES_VIEWS.get(status.series()), model);}return modelAndView;}// 在类路径下,查看是否存在 error/错误码 的模板引擎,存在就返回该视图;// 否则去下面的4个CLASSPATH_RESOURCE_LOCATIONS路径下,查看是否写了  error/错误码.html 的页面,存在则返回该视图private ModelAndView resolve(String viewName, Map<String, Object> model) {String errorViewName = "error/" + viewName;TemplateAvailabilityProvider provider = this.templateAvailabilityProviders.getProvider(errorViewName,this.applicationContext);if (provider != null) {return new ModelAndView(errorViewName, model);}return resolveResource(errorViewName, model);}//去下面的4个CLASSPATH_RESOURCE_LOCATIONS路径下,查看是否写了  error/错误码.html  的页面,存在则返回该视图//this.resources.getStaticLocations()//private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",//			"classpath:/resources/", "classpath:/static/", "classpath:/public/" };private ModelAndView resolveResource(String viewName, Map<String, Object> model) {for (String location : this.resources.getStaticLocations()) {try {Resource resource = this.applicationContext.getResource(location);resource = resource.createRelative(viewName + ".html");if (resource.exists()) {return new ModelAndView(new HtmlResourceView(resource), model);}}catch (Exception ex) {}}return null;}...
    }
    
  • 5.在ErrorMvcAutoConfiguration自动装配类中,向容器中放入了一个默认名为error的视图,提供了默认的白页功能,如果上述都无法处理

    	@Configuration(proxyBeanMethods = false)@ConditionalOnProperty(prefix = "server.error.whitelabel", name = "enabled", matchIfMissing = true)@Conditional(ErrorTemplateMissingCondition.class)protected static class WhitelabelErrorViewConfiguration {private final StaticView defaultErrorView = new StaticView();//   注入了error视图@Bean(name = "error")@ConditionalOnMissingBean(name = "error")public View defaultErrorView() {return this.defaultErrorView;}// If the user adds @EnableWebMvc then the bean name view resolver from// WebMvcAutoConfiguration disappears, so add it back in to avoid disappointment.@Bean@ConditionalOnMissingBeanpublic BeanNameViewResolver beanNameViewResolver() {BeanNameViewResolver resolver = new BeanNameViewResolver();resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);return resolver;}}
    

    默认的白页源码,就在类ErrorMvcAutoConfiguration中定义的

    private static class StaticView implements View {private static final MediaType TEXT_HTML_UTF8 = new MediaType("text", "html", StandardCharsets.UTF_8);private static final Log logger = LogFactory.getLog(StaticView.class);@Overridepublic void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)throws Exception {if (response.isCommitted()) {String message = getMessage(model);logger.error(message);return;}response.setContentType(TEXT_HTML_UTF8.toString());StringBuilder builder = new StringBuilder();Object timestamp = model.get("timestamp");Object message = model.get("message");Object trace = model.get("trace");if (response.getContentType() == null) {response.setContentType(getContentType());}builder.append("<html><body><h1>Whitelabel Error Page</h1>").append("<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>").append("<div id='created'>").append(timestamp).append("</div>").append("<div>There was an unexpected error (type=").append(htmlEscape(model.get("error"))).append(", status=").append(htmlEscape(model.get("status"))).append(").</div>");if (message != null) {builder.append("<div>").append(htmlEscape(message)).append("</div>");}if (trace != null) {builder.append("<div style='white-space:pre-wrap;'>").append(htmlEscape(trace)).append("</div>");}builder.append("</body></html>");response.getWriter().append(builder.toString());}private String htmlEscape(Object input) {return (input != null) ? HtmlUtils.htmlEscape(input.toString()) : null;}private String getMessage(Map<String, ?> model) {Object path = model.get("path");String message = "Cannot render error page for request [" + path + "]";if (model.get("message") != null) {message += " and exception [" + model.get("message") + "]";}message += " as the response has already been committed.";message += " As a result, the response may have the wrong status code.";return message;}@Overridepublic String getContentType() {return "text/html";}}
    
  • 6.在ErrorMvcAutoConfiguration自动装配类中,封装了JSON格式的错误信息(初始化了错误的类型、错误的状态码、路径、栈信息、时间戳等信息)

    @Bean
    @ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
    public DefaultErrorAttributes errorAttributes() {return new DefaultErrorAttributes();
    }
    
规则如下:
  • 1.解析一个错误页:

    • 如果发生了500、404、503、403 这些错误
        1. 如果有模板引擎,默认在 classpath:/templates/error/精确码.html
        1. 如果没有模板引擎,在静态资源文件夹下找 精确码.html
    • 如果匹配不到精确码.html这些精确的错误页,就去找5xx.html4xx.html模糊匹配
        1. 如果有模板引擎,默认在 classpath:/templates/error/5xx.html
        1. 如果没有模板引擎,在静态资源文件夹下找 5xx.html
  • 2.如果模板引擎路径templates下有 error.html页面,就直接渲染

5、自定义错误响应

​ 1) 自定义json响应:使用文章第2和第3部分介绍的,使用注解进行统一的异常处理

​ 2)自定义页面响应:根据第4部分介绍的规则,在对应的项目路径"classpath:/METAINF/resources/","classpath:/resources/","classpath:/static/", "classpath:/public/"或者模板引擎目录下,定义错误页面即可。

6、测试

1、在项目的resources/templates/目录下创建一个error文件夹,放入4xx.html、5xx.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>4xx.html
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
5xx.html
</body>
</html>
2、在项目的resources/templates/error文件夹中,再放入404.html、500.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
404.html
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
500.html
</body>
</html>
3、浏览器先后测试上述情况
  • 1.访问一个不存在的路径;
  • 2.制造除0错误。

相关文章:

SpringBoot错误处理机制解析

SpringBoot错误处理----源码解析 文章目录 1、默认机制2、使用ExceptionHandler标识一个方法&#xff0c;处理用Controller标注的该类发生的指定错误1&#xff09;.局部错误处理部分源码2&#xff09;.测试 3、 创建一个全局错误处理类集中处理错误&#xff0c;使用Controller…...

牛客剑指offer刷题模拟篇

文章目录 顺时针打印矩阵题目思路代码实现 扑克牌顺子题目思路代码实现 把字符串转换成整数题目思路代码实现 表示数值的字符串题目思路代码实现 顺时针打印矩阵 题目 描述 输入一个矩阵&#xff0c;按照从外向里以顺时针的顺序依次打印出每一个数字&#xff0c;例如&#xf…...

Locust单机多核压测,以及主从节点的数据通信处理!

一、背景 这还是2个月前做的一次接口性能测试&#xff0c;关于locust脚本的单机多核运行&#xff0c;以及主从节点之间的数据通信。 先简单交代下背景&#xff0c;在APP上线之前&#xff0c;需要对登录接口进行性能测试。经过评估&#xff0c;我还是优先选择了locust来进行脚…...

ERROR: [pool www] please specify user and group other than root

根据提供的日志信息&#xff0c;PHP-FPM 服务未能启动的原因是配置文件中的一个错误。错误消息明确指出了问题所在&#xff1a; [29-Nov-2023 14:28:26] ERROR: [pool www] please specify user and group other than root [29-Nov-2023 14:28:26] ERROR: FPM initialization …...

京东商品详情接口在电商行业中的重要性及实时数据获取实现

一、引言 随着电子商务的快速发展&#xff0c;商品信息的准确性和实时性对于电商行业的运营至关重要。京东作为中国最大的电商平台之一&#xff0c;其商品详情接口在电商行业中扮演着重要的角色。本文将深入探讨京东商品详情接口的重要性&#xff0c;并介绍如何通过API实现实时…...

WT2003H MP3语音芯片方案:强大、灵活且易于集成的音频解决方案

在当今的数字化时代&#xff0c;音频技术的普遍性已不容忽视。从简单的音乐播放&#xff0c;到复杂的语音交互&#xff0c;音频技术的身影无处不在。在这个背景下&#xff0c;WT2003H MP3语音芯片方案应运而生&#xff0c;它提供了一种强大、灵活且易于集成的音频解决方案。 1…...

机器学习深度学学习分类模型中常用的评价指标总结记录与代码实现说明

在机器学习深度学习算法模型大开发过程中&#xff0c;免不了要对算法模型进行对应的评测分析&#xff0c;这里主要是总结记录分类任务中经常使用到的一些评价指标&#xff0c;并针对性地给出对应的代码实现&#xff0c;方便读者直接移植到自己的项目中。 【混淆矩阵】 混淆矩阵…...

fastapi 后端项目目录结构 mysql fastapi 数据库操作

原文&#xff1a;fastapi 后端项目目录结构 mysql fastapi 数据库操作_mob6454cc786d85的技术博客_51CTO博客 一、安装sqlalchemy、pymysql模块 pip install sqlalchemy -i https://pypi.tuna.tsinghua.edu.cn/simple pip install pymysql -i https://pypi.tuna.tsinghua.edu.…...

研习代码 day47 | 动态规划——子序列问题3

一、判断子序列 1.1 题目 给定字符串 s 和 t &#xff0c;判断 s 是否为 t 的子序列。 字符串的一个子序列是原始字符串删除一些&#xff08;也可以不删除&#xff09;字符而不改变剩余字符相对位置形成的新字符串。&#xff08;例如&#xff0c;"ace"是"abcde&…...

L1-017:到底有多二

题目描述 一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数&#xff0c;则程度增加0.5倍&#xff1b;如果还是个偶数&#xff0c;则再增加1倍。例如数字-13142223336是个11位数&#xff0c;其中有3个2&#xff0c;并且是负数&#xff0c;也是…...

Python多线程使用(二)

使用多个线程的时候容易遇到一个场景&#xff1a;多个线程处理一份数据 使用多线程的时候同时处理一份数据&#xff0c;在threading中提供了一个方法&#xff1a;线程锁 Demo&#xff1a;下订单 现在有多笔订单下单&#xff0c;库存减少 from threading import Thread from t…...

记录一次docker搭建tomcat容器的网页不能访问的问题

tomcat Tomcat是Apache软件基金会的Jakarta项目中的一个重要子项目&#xff0c;是一个Web服务器&#xff0c;也是Java应用服务器&#xff0c;是开源免费的软件。它是一个兼容Java Servlet和JavaServer Pages&#xff08;JSP&#xff09;的Web服务器&#xff0c;可以作为独立的W…...

GPT3年终总结

User You 程序员年度绩效总结 ChatGPT ChatGPT 程序员年度绩效总结通常包括以下几个方面&#xff1a; 目标达成情况&#xff1a; 回顾年初设定的目标&#xff0c;评估在项目完成、技能提升等方面的达成情况。 工作贡献&#xff1a; 强调在项目中的个人贡献&#xff0c;包括…...

Kafka生产者发送消息的流程

Kafka 生产者发送消息的流程涉及多个步骤&#xff0c;从消息的创建到成功存储在 Kafka 集群中。以下是 Kafka 生产者发送消息的主要步骤&#xff1a; 1. 创建消息 生产者首先创建一个消息&#xff0c;消息通常包含一个键&#xff08;可选&#xff09;和一个值&#xff0c;以及…...

基于SSM的数学竞赛网站设计与实现

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…...

01-使用Git操作本地库,如初始化本地库,提交工作区文件到暂存区和本地库,查看版本信息,版本切换命令等

Git的使用 概述 Git是一个分布式版本控制工具, 通常用来管理项目中的源代码文件(Java类、xml文件、html页面等)进行管理,在软件开发过程中被广泛使用 Git可以记录文件修改的历史记录并形成备份从而实现代码回溯, 版本切换, 多人协作, 远程备份的功能Git具有廉价的本地库,方便…...

排序算法介绍(二)冒泡排序

0. 简介 冒泡排序&#xff08;Bubble Sort&#xff09;是一种简单的排序算法。它重复地遍历要排序的数列&#xff0c;一次比较两个元素&#xff0c;如果他们的顺序错误就把他们交换过来。遍历数列的工作是重复地进行直到没有再需要交换&#xff0c;也就是说该数列已经排…...

搜索引擎高级用法总结: 谷歌、百度、必应

搜索引擎高级用法总结: 谷歌、百度、必应 google search 基本搜索 逻辑与:and逻辑或: or逻辑非: -完整匹配:“关键词”通配符:* ?高级搜索 intext:后台登录 将只返回正文中包含 后台登录 的网页 intitle intitle:后台登录 将只返回标题中包含 后台登录 的网页,intitle…...

com.intellij.openapi.application.ApplicationListener使用

一般监听期通过如下代码生效 <applicationListeners> <!-- <listener class"com.itheima.taunt.MyApplicationListener"--> <!-- topic"com.intellij.openapi.application.ApplicationListener"…...

常见js hook脚本

一.js hook 过无限debugger var _constructor constructor; Function.prototype.constructor function(s) {if (s "debugger") {console.log(s);return null;}return _constructor(s); }//去除无限debugger Function.prototype.__constructor_back Function.pro…...

JVM 内存结构 详解

内存结构 运行时数据区&#xff1a; Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器&#xff1a; ​ 线程私有&#xff0c;程序控制流的指示器&#xff0c;分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 ​ 每个线程都有一个程序计数…...

Redis:现代应用开发的高效内存数据存储利器

一、Redis的起源与发展 Redis最初由意大利程序员Salvatore Sanfilippo在2009年开发&#xff0c;其初衷是为了满足他自己的一个项目需求&#xff0c;即需要一个高性能的键值存储系统来解决传统数据库在高并发场景下的性能瓶颈。随着项目的开源&#xff0c;Redis凭借其简单易用、…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...

实战三:开发网页端界面完成黑白视频转为彩色视频

​一、需求描述 设计一个简单的视频上色应用&#xff0c;用户可以通过网页界面上传黑白视频&#xff0c;系统会自动将其转换为彩色视频。整个过程对用户来说非常简单直观&#xff0c;不需要了解技术细节。 效果图 ​二、实现思路 总体思路&#xff1a; 用户通过Gradio界面上…...

Python竞赛环境搭建全攻略

Python环境搭建竞赛技术文章大纲 竞赛背景与意义 竞赛的目的与价值Python在竞赛中的应用场景环境搭建对竞赛效率的影响 竞赛环境需求分析 常见竞赛类型&#xff08;算法、数据分析、机器学习等&#xff09;不同竞赛对Python版本及库的要求硬件与操作系统的兼容性问题 Pyth…...

高分辨率图像合成归一化流扩展

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 1 摘要 我们提出了STARFlow&#xff0c;一种基于归一化流的可扩展生成模型&#xff0c;它在高分辨率图像合成方面取得了强大的性能。STARFlow的主要构建块是Transformer自回归流&#xff08;TARFlow&am…...

echarts使用graphic强行给图增加一个边框(边框根据自己的图形大小设置)- 适用于无法使用dom的样式

pdf-lib https://blog.csdn.net/Shi_haoliu/article/details/148157624?spm1001.2014.3001.5501 为了完成在pdf中导出echarts图&#xff0c;如果边框加在dom上面&#xff0c;pdf-lib导出svg的时候并不会导出边框&#xff0c;所以只能在echarts图上面加边框 grid的边框是在图里…...

如何把工业通信协议转换成http websocket

1.现状 工业通信协议多数工作在边缘设备上&#xff0c;比如&#xff1a;PLC、IOT盒子等。上层业务系统需要根据不同的工业协议做对应开发&#xff0c;当设备上用的是modbus从站时&#xff0c;采集设备数据需要开发modbus主站&#xff1b;当设备上用的是西门子PN协议时&#xf…...

02-性能方案设计

需求分析与测试设计 根据具体的性能测试需求&#xff0c;确定测试类型&#xff0c;以及压测的模块(web/mysql/redis/系统整体)前期要与相关人员充分沟通&#xff0c;初步确定压测方案及具体的性能指标QA完成性能测试设计后&#xff0c;需产出测试方案文档发送邮件到项目组&…...

WinUI3开发_使用mica效果

简介 Mica(云母)是Windows10/11上的一种现代化效果&#xff0c;是Windows10/11上所使用的Fluent Design(设计语言)里的一个效果&#xff0c;Windows10/11上所使用的Fluent Design皆旨在于打造一个人类、通用和真正感觉与 Windows 一样的设计。 WinUI3就是Windows10/11上的一个…...