目录

  • 一、介绍
  • 二、源码分析
    • 2.1 convertIfNecessary 方法解析
    • 2.2 findDefaultEditor 方法解析
    • 2.3 doConvertValue 方法解析
    • 2.3 convertToTypedArray方法解析
    • 2.3 convertToTypedCollection方法解析
  • 三、小结

一、介绍

TypeConverter 类主要是 负责类型转换,其实现类是 TypeConverterSupport,但是所有的具体实现都是在TypeConverterDelegate 里面完成的.

二、源码分析

TypeConverterDelegate 里面总共包含的方法如下:
在这里插入图片描述
这里主要分析一些主要的方法

2.1 convertIfNecessary 方法解析

public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {// 根据requiredType 和 propertyName 获取对应的定制编辑器PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);ConversionFailedException conversionAttemptEx = null;// 获取对应的conversionServiceConversionService conversionService = this.propertyEditorRegistry.getConversionService();if (editor == null && conversionService != null && newValue != null && typeDescriptor != null) {// 为newValue 创建一个类型描述器TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);// 判断是否能sourceTypeDesc 转换为需要的typeDescriptor,如果可以//直接调用conversionService.convert 进行返回if (conversionService.canConvert(sourceTypeDesc, typeDescriptor)) {try {return (T) conversionService.convert(newValue, sourceTypeDesc, typeDescriptor);}catch (ConversionFailedException ex) {// fallback to default conversion logic belowconversionAttemptEx = ex;}}}Object convertedValue = newValue;// 自定义editor 不为空 或者 对应的值 不是 需要的类型if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {// 如果需要的类型是集合类型,并且值是String 类型(String⇒ 集合)if (typeDescriptor != null && requiredType != null && Collection.class.isAssignableFrom(requiredType) &&convertedValue instanceof String) {// 获取集合里面元素的类型描述器TypeDescriptor elementTypeDesc = typeDescriptor.getElementTypeDescriptor();if (elementTypeDesc != null) {// 获取对应的类型Class<?> elementType = elementTypeDesc.getType();if (Class.class == elementType || Enum.class.isAssignableFrom(elementType)) {//将String字符串逗号分隔开,转换成字符串数组convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);}}}//如果自定义编辑器 为null,就根据requiredType 设置相对应的编辑器if (editor == null) {editor = findDefaultEditor(requiredType);}//对convertedValue 进行相关的转换convertedValue = doConvertValue(oldValue, convertedValue, requiredType, editor);}boolean standardConversion = false;if (requiredType != null) {// 这里都是一些标准的类型转换 ,根据各种类型调用相应的方法if (convertedValue != null) {// 如果是Object类型,直接强制转换并返回if (Object.class == requiredType) {return (T) convertedValue;}else if (requiredType.isArray()) {//如果需要的类型是枚举类型if (convertedValue instanceof String && Enum.class.isAssignableFrom(requiredType.getComponentType())) {// 先将 转换为 逗号分隔的String 数组convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);}// 转换为数组return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());}else if (convertedValue instanceof Collection) {//如果convertedValue 是集合类型 ,进行相关的转换convertedValue = convertToTypedCollection((Collection<?>) convertedValue, propertyName, requiredType, typeDescriptor);standardConversion = true;}else if (convertedValue instanceof Map) {// 如果确定,将键和值转换为相应的目标类型convertedValue = convertToTypedMap((Map<?, ?>) convertedValue, propertyName, requiredType, typeDescriptor);standardConversion = true;}// 如果convertedValue 是数组类型,并且 长度为1 ,那就把get(0) 赋值给本身if (convertedValue.getClass().isArray() && Array.getLength(convertedValue) == 1) {convertedValue = Array.get(convertedValue, 0);standardConversion = true;}// 如果需要的类型是 String ,并且convertedValue 的类型是基本类型或者装箱类型,那就直接toString 后强行转换if (String.class == requiredType && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) {// We can stringify any primitive value...return (T) convertedValue.toString();}else if (convertedValue instanceof String && !requiredType.isInstance(convertedValue)) {if (conversionAttemptEx == null && !requiredType.isInterface() && !requiredType.isEnum()) {try {Constructor<T> strCtor = requiredType.getConstructor(String.class);return BeanUtils.instantiateClass(strCtor, convertedValue);}catch (NoSuchMethodException ex) {// proceed with field lookupif (logger.isTraceEnabled()) {logger.trace("No String constructor found on type [" + requiredType.getName() + "]", ex);}}catch (Exception ex) {if (logger.isDebugEnabled()) {logger.debug("Construction via String failed for type [" + requiredType.getName() + "]", ex);}}}String trimmedValue = ((String) convertedValue).trim();if (requiredType.isEnum() && trimmedValue.isEmpty()) {// It's an empty enum identifier: reset the enum value to null.return null;}convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue);standardConversion = true;}else if (convertedValue instanceof Number && Number.class.isAssignableFrom(requiredType)) {convertedValue = NumberUtils.convertNumberToTargetClass((Number) convertedValue, (Class<Number>) requiredType);standardConversion = true;}}else {// convertedValue == nullif (requiredType == Optional.class) {convertedValue = Optional.empty();}}if (!ClassUtils.isAssignableValue(requiredType, convertedValue)) {if (conversionAttemptEx != null) {// Original exception from former ConversionService call above...throw conversionAttemptEx;}else if (conversionService != null && typeDescriptor != null) {// ConversionService not tried before, probably custom editor found// but editor couldn't produce the required type...TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);if (conversionService.canConvert(sourceTypeDesc, typeDescriptor)) {return (T) conversionService.convert(newValue, sourceTypeDesc, typeDescriptor);}}// Definitely doesn't match: throw IllegalArgumentException/IllegalStateExceptionStringBuilder msg = new StringBuilder();msg.append("Cannot convert value of type '").append(ClassUtils.getDescriptiveType(newValue));msg.append("' to required type '").append(ClassUtils.getQualifiedName(requiredType)).append("'");if (propertyName != null) {msg.append(" for property '").append(propertyName).append("'");}if (editor != null) {msg.append(": PropertyEditor [").append(editor.getClass().getName()).append("] returned inappropriate value of type '").append(ClassUtils.getDescriptiveType(convertedValue)).append("'");throw new IllegalArgumentException(msg.toString());}else {msg.append(": no matching editors or conversion strategy found");throw new IllegalStateException(msg.toString());}}}if (conversionAttemptEx != null) {if (editor == null && !standardConversion && requiredType != null && Object.class != requiredType) {throw conversionAttemptEx;}logger.debug("Original ConversionService attempt failed - ignored since " +"PropertyEditor based conversion eventually succeeded", conversionAttemptEx);}return (T) convertedValue;}

2.2 findDefaultEditor 方法解析

	private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {PropertyEditor editor = null;if (requiredType != null) {// No custom editor -> check BeanWrapperImpl's default editors.editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);if (editor == null && String.class != requiredType) {// No BeanWrapper default editor -> check standard JavaBean editor.editor = BeanUtils.findEditorByConvention(requiredType);}}return editor;}

2.3 doConvertValue 方法解析

private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,@Nullable Class<?> requiredType, @Nullable PropertyEditor editor) {Object convertedValue = newValue;// 如果编辑器不为null ,并且 转换值的类型不是 Stringif (editor != null && !(convertedValue instanceof String)) {// 调用setValue 方法//如果使用标准的PropertyEditors 的话,那就返回的是完全一样的对象,// 这里是调用专门的编辑器的setValue方法进行从非String 转到需要的类型上try {editor.setValue(convertedValue);Object newConvertedValue = editor.getValue();// 如果不一样,就说明进行了转换,需要将convertedValue 替换为转换后的值if (newConvertedValue != convertedValue) {convertedValue = newConvertedValue;// 这里将editor 置空,editor 已经进行了正确的转换,不需要再将其用于setAsText 的调用editor = null;}}catch (Exception ex) {if (logger.isDebugEnabled()) {logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);}// 这里没有抛出异常,而是继续运行下面的代码}}Object returnValue = convertedValue;// 如果convertedValue  是String[] 数组类型,而需要的类型不是数组类型// 那就先将convertedValue 转换为 逗号分隔的String 值if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) {if (logger.isTraceEnabled()) {logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");}// 将 String 数组 转换为 逗号分隔的String 值convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue);}if (convertedValue instanceof String) {if (editor != null) {if (logger.isTraceEnabled()) {logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");}String newTextValue = (String) convertedValue;// 调用 PropertyEditor 的setAsTextreturn doConvertTextValue(oldValue, newTextValue, editor);}// 如果requiredType 是String ,直接赋值并返回else if (String.class == requiredType) {returnValue = convertedValue;}}return returnValue;}

2.3 convertToTypedArray方法解析

private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {// 如果input 是集合类型if (input instanceof Collection) {// 将集合元素转换为数组元素Collection<?> coll = (Collection<?>) input;Object result = Array.newInstance(componentType, coll.size());int i = 0;for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) {// 进行遍历,对逐个元素进行转换Object value = convertIfNecessary(buildIndexedPropertyName(propertyName, i), null, it.next(), componentType);Array.set(result, i, value);}return result;}// 如果输入的数组类型else if (input.getClass().isArray()) {// 对数组里面的元素进行 逐个转换(可能类型一样就不要转换)if (componentType.equals(input.getClass().getComponentType()) &&!this.propertyEditorRegistry.hasCustomEditorForElement(componentType, propertyName)) {return input;}int arrayLength = Array.getLength(input);Object result = Array.newInstance(componentType, arrayLength);for (int i = 0; i < arrayLength; i++) {Object value = convertIfNecessary(buildIndexedPropertyName(propertyName, i), null, Array.get(input, i), componentType);Array.set(result, i, value);}return result;}else {//输入input 既不是集合类型,也不是数组类型,但是要转为数组// 就整个转化为一个元素的数组Object result = Array.newInstance(componentType, 1);Object value = convertIfNecessary(buildIndexedPropertyName(propertyName, 0), null, input, componentType);Array.set(result, 0, value);return result;}}

2.3 convertToTypedCollection方法解析

private Collection<?> convertToTypedCollection(Collection<?> original, @Nullable String propertyName,Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {// 如果requiredType 不是集合类型,直接返回if (!Collection.class.isAssignableFrom(requiredType)) {return original;}// 判断是否是 集合相近的,比如:List,set,ArrayList..boolean approximable = CollectionFactory.isApproximableCollectionType(requiredType);//不是集合相近的,并且也不能对requiredType复制-注入原始Collectionif (!approximable && !canCreateCopy(requiredType)) {if (logger.isDebugEnabled()) {logger.debug("Custom Collection type [" + original.getClass().getName() +"] does not allow for creating a copy - injecting original Collection as-is");}return original;}boolean originalAllowed = requiredType.isInstance(original);TypeDescriptor elementType = (typeDescriptor != null ? typeDescriptor.getElementTypeDescriptor() : null);// 集合里面没有指定类型,并且original 就是 requiredType 类型,propertyEditorRegistry里面也没有对应的自定义编辑器,就直接返回if (elementType == null && originalAllowed &&!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {return original;}Iterator<?> it;try {it = original.iterator();}catch (Throwable ex) {if (logger.isDebugEnabled()) {logger.debug("Cannot access Collection of type [" + original.getClass().getName() +"] - injecting original Collection as-is: " + ex);}return original;}Collection<Object> convertedCopy;try {if (approximable) {convertedCopy = CollectionFactory.createApproximateCollection(original, original.size());}else {convertedCopy = (Collection<Object>)ReflectionUtils.accessibleConstructor(requiredType).newInstance();}}catch (Throwable ex) {if (logger.isDebugEnabled()) {logger.debug("Cannot create copy of Collection type [" + original.getClass().getName() +"] - injecting original Collection as-is: " + ex);}return original;}int i = 0;// 遍历,进行转换for (; it.hasNext(); i++) {Object element = it.next();String indexedPropertyName = buildIndexedPropertyName(propertyName, i);Object convertedElement = convertIfNecessary(indexedPropertyName, null, element,(elementType != null ? elementType.getType() : null) , elementType);try {convertedCopy.add(convertedElement);}catch (Throwable ex) {if (logger.isDebugEnabled()) {logger.debug("Collection type [" + original.getClass().getName() +"] seems to be read-only - injecting original Collection as-is: " + ex);}return original;}originalAllowed = originalAllowed && (element == convertedElement);}return (originalAllowed ? original : convertedCopy);}// 不是接口、不是抽象类、public 类型、有对应的构造方法private boolean canCreateCopy(Class<?> requiredType) {return (!requiredType.isInterface() && !Modifier.isAbstract(requiredType.getModifiers()) &&Modifier.isPublic(requiredType.getModifiers()) && ClassUtils.hasConstructor(requiredType));}

三、小结

这里面的方法都是类型转换相关的.

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

相关文章

  1. 大黑谈币:比特币上涨无力 后续如何操作

    肉弱强食是这里的规矩,几率是执行线路的唯一保证,无论是什么样的投资,永远不要拿明天的钱去博弈没有把握的利润。一个人的承受能力是有限的。同样在这个过程中,不要情绪化交易,与市场斗气,那吃亏的只有你们自己。一个只会享受价格的震荡,却拒绝资金震荡的人,是很难生存…...

    2024/4/28 5:56:29
  2. 【Tools】Linux串口设备调试技巧(sftty)

    文章目录前言读取串口设备数据往串口设备写数据串口设备参数访问查看串口设备参数设置串口设备参数前言串口设备是linux系统中最基本的设备之一,在嵌入式linux开发中几乎是必不可少的。由于串口使用简单、广泛,除了使用一路串口作为调试终端输出外,还会使用串口作为外部设备…...

    2024/4/28 8:04:44
  3. leetcode 29. 两数相除

    题目 给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。 返回被除数 dividend 除以除数 divisor 得到的商。 整数除法的结果应当截去(truncate)其小数部分,例如:truncate(8.345) = 8 以及 truncate(-2.7335) = -2示例 1: 输…...

    2024/4/28 6:48:30
  4. Mybatis——缓存

    MyBatis 有一级和二级缓存,还有一个可以借助第三方缓存实现的自定义缓存。 1. 一级缓存:一级缓存也叫本地(会话)缓存。作用域在Sqlsession(即,从sqlsession创建到sqlsession close)查询同一个数据时,第一次会去访问数据库,后面直接从缓存中获取。结果如下:可以看出,两…...

    2024/4/28 3:49:38
  5. 组会内容准备

    1. SU(N) Hubbard 模型的平带铁磁性2. 背景巡游电子铁磁性是凝聚态物理中很重要的一个问题。巡游电子铁磁性通常被认为是电子与电子之间的强关联的结果,通常能用Hubbard模型描述。下面这个就是Hubbard模型的哈密顿量,第一项是Hopping项,第二项就是Hubbard相互作用项,当一个…...

    2024/4/20 4:18:25
  6. springboot使用Mybatis的步骤

    创建一个maven-jar新项目 项目结构 pom导入 在pom.xml文件中加入<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><d…...

    2024/4/28 8:43:07
  7. web前端笔记day5

    定位 一个大盒子要先被定义成“相对定位relative”,然后在大盒子中的小盒子再设置“绝对定位absolute”并利用left、top、right、bottom来调整图片或其他控件来达到想要的位置。 #weChat{ display:flex;/*定义弹性布局*/ justify-content:space-between;/*弹性布局的子节点两边…...

    2024/4/28 11:50:01
  8. VS2019编译OpenCV3.4库 C/C++ (超详细)

    目录前言一、获取OpenCV 3.4源码二、准备工作目录三、编译生成x64库四、编译生成x86的库前言一开始直接从GitHub上面git clone opencv的库编译完发现与市面上的算法程序不兼容,后面才发现直接从GitHub上面clone下来的Master分支的是opencv4的源代码。于是乎,重新clone了OpenC…...

    2024/4/28 6:41:20
  9. 傅里叶分析

    傅里叶分析(详细讲解) 个人感觉 这篇文章 讲解的非常好,转自 知乎文章 原文链接地址: https://zhuanlan.zhihu.com/p/19763358...

    2024/4/9 19:30:32
  10. HDU - 3001 Travelling(三进制状压DP)

    本来是在搜索专题里看到的这道题,搜索没写过去,评论区看到有人说是三进制状压,就搜索相关资料学习了一下。 HDU - 3001 TravellingN进制状态压缩 关于二进制的状压,可以用移位符轻松解决,具体说明可以参考《挑战》P156,除二进制以外的进制压缩需要通过以下方法实现:(从…...

    2024/4/28 6:00:06
  11. 1.15。ApplicationContext的附加功能 【spring 核心技术 翻译】

    1.15。ApplicationContext的附加功能 正如在引言中所讨论的,org.springframework.beans.factory 包提供了管理和操作bean的基本功能,包括以编程的方式。org.springframework.context 包添加了ApplicationContext接口,它扩展了BeanFactory接口,此外还扩展了其他接口,以更面…...

    2024/4/28 7:24:51
  12. 配置桥接网络

    方法一:图形化配置[root@localhost Desktop]# nm-connection-editorDHCP自动获取地址检查:[root@localhost ~]# nmcli con show [root@lh ~]# ip a方法二:命令行配置1、设置添加一块新网卡[root@localhost ~]# nmcli device status DEVICE TYPE STATE CONNECTIO…...

    2024/4/27 15:33:59
  13. R语言 KM曲线作图及logrank检验

    高低危分两组 library("survival") library("survminer")# best cutoffres.cut <- surv_cutpoint(RC_N, time = "time", event = "event", variables = c("value"))res.cat <- surv_categorize(res.cut)fit <- sur…...

    2024/4/27 16:16:52
  14. servelet+jsp+jdbc实现简单增删改查

    servelet+jsp+jdbc实现简单增删改查1、sql建表语句2、目录结构3、实体类4、servlet类5、utils工具类6、jsp页面 1、sql建表语句SET FOREIGN_KEY_CHECKS=0;DROP TABLE IF EXISTS `employee`; CREATE TABLE `employee` (`Operater_id` int(20) DEFAULT NULL COMMENT ,`Name` varc…...

    2024/4/28 3:59:50
  15. 人们只有到了具体情境才知道自己真正想要的是什么

    ​1. 人们很少做不加对比的选择。我们的心里并没有一个“内部价值计量器”来告诉我们某种物品真正的价值是多少。相反,我们关注的是这种物品和其他物品的相对优劣,以此来估算其价值。比如,我们不知道六核的电脑的卖多少钱,但我们肯定可以推断出它比四核的要贵。这是怎么回事…...

    2024/4/28 9:03:34
  16. make: *** No rule to make target `build‘, needed by `default‘. Stop.

    解决Centos7 解决安装Nginx编辑make && make install的不成功make: *** No rule to make target `build, needed by `default. Stop.解决方案1、安装下面配置yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel2、重新configure./configure 3、编…...

    2024/4/27 9:52:14
  17. 【JavaWeb】Springcloud入门(1)Http通信+Eureka+Ribbon

    一、前言金手指:分布式与微服务的关系 分布式更多的与集群联系在一起,部署方式。 微服务更多是服务间调用、数据交互。金手指:分布式和高并发 分布式是一个部署方式,高并发是指并发量大,使用集群来应对,分布式和高并发联系在一起。Spring提供了一个RestTemplate模板工具类…...

    2024/4/9 19:30:27
  18. 高精快速幂——洛谷P1045麦森数~2020.7.14学习笔记

    输入输出样例 输入: 1279 输出: 386 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000104079321946643990819252403273640855 38615262247266704805319112350403608059673360298012 2394417323241848…...

    2024/4/9 19:30:26
  19. 专业课习题 0714

    数据结构 1.一个栈的输入序列为123…n,若输出序列的第一个元素是n,输出的第i(1<=i<=n)个元素是 [中山大学1999 一、9(1 分)] A. 不确定 B. n-i C. i D. n-i+1 答案:按照后进先出的规律,可以采用带入I = 1,可以快速得到答案 计算机网络 2.HDLC协议所采用的帧同步…...

    2024/4/18 10:24:04
  20. JAVA中创建线程thread.start方法

    java中创建一个新的线程有多种方式,如new Thread,实现runnable,实现callball;但归根结底都是new Thread,重写run方法。如果调用run方法,则只是使用当前线程调用了一个普通的方法,而不是new Thread执行run方法。执行Thread.start方法的源码:public class Thread impleme…...

    2024/4/24 0:02:04

最新文章

  1. Github创建远程仓库(项目)

    天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物。 每个人都有惰性&#xff0c;但不断学习是好好生活的根本&#xff0c;共勉&#xff01; 文章均为学习整理笔记&#xff0c;分享记录为主&#xff0c;如有错误请指正&#xff0c;共同学习进步。…...

    2024/4/28 14:55:46
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. jenkins参数化构建

    Jenkins 的参数化构建 Jenkins 是一个开源的持续集成和持续部署工具&#xff0c;它可以帮助开发者自动化构建、测试和部署软件项目。在本文中&#xff0c;我们将重点介绍如何使用 Jenkins 的参数化构建功能来创建更加灵活和可定制的项目。 参数化构建是 Jenkins 提供的一种强…...

    2024/4/26 6:03:34
  4. spark on hive

    由于spark不存在元数据管理模块&#xff0c;为了能方便地通过sql操作hdfs数据&#xff0c;我们可以通过借助hive的元数据管理模块实现。对于hive来说&#xff0c;核心组件包含两个&#xff1a; sql优化翻译器&#xff0c;翻译sql到mapreduce并提交到yarn执行metastore&#xf…...

    2024/4/27 18:57:26
  5. JVM笔记

    1.JVM与Java体系结构 1.1. 前言 作为Java工程师的你曾被伤害过吗&#xff1f;你是否也遇到过这些问题&#xff1f; 运行着的线上系统突然卡死&#xff0c;系统无法访问&#xff0c;甚至直接OOM想解决线上JVM GC问题&#xff0c;但却无从下手新项目上线&#xff0c;对各种JVM…...

    2024/4/26 0:12:59
  6. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/4/28 4:04:40
  7. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/4/28 12:01:04
  8. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/4/27 12:24:35
  9. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/4/27 12:24:46
  10. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/4/28 12:01:03
  11. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/4/28 12:01:03
  12. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/4/28 12:01:03
  13. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/4/27 12:44:49
  14. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/4/27 21:08:20
  15. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/4/28 9:00:42
  16. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/4/27 18:40:35
  17. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/4/28 4:14:21
  18. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/4/27 13:52:15
  19. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/4/27 13:38:13
  20. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/4/28 12:00:58
  21. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/4/28 12:00:58
  22. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/4/27 22:51:49
  23. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/4/28 7:31:46
  24. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/4/28 8:32:05
  25. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/4/27 20:28:35
  26. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  27. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  28. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  29. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  30. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  31. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  32. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  33. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  34. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  35. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  36. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  37. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  38. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  39. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  40. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  41. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  42. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  43. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  44. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  45. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57