Spring源码解析——IOC属性填充

正文

doCreateBean() 主要用于完成 bean 的创建和初始化工作,我们可以将其分为四个过程:

最全面的Java面试网站

  • createBeanInstance() 实例化 bean
  • populateBean() 属性填充
  • 循环依赖的处理
  • initializeBean() 初始化 bean

第一个过程实例化 bean在前面一篇博客中已经分析完了,这篇博客开始分析 属性填充,也就是 populateBean()

protected void populateBean(String beanName, RootBeanDefinition mbd, BeanWrapper bw) {  PropertyValues pvs = mbd.getPropertyValues();  if (bw == null) {  if (!pvs.isEmpty()) {  throw new BeanCreationException(  mbd.getResourceDescription(), beanName, "Cannot apply property values to null instance");  }  else {  // Skip property population phase for null instance.  return;  }  }  // Give any InstantiationAwareBeanPostProcessors the opportunity to modify the  // state of the bean before properties are set. This can be used, for example,  // to support styles of field injection.  boolean continueWithPropertyPopulation = true;  if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {  for (BeanPostProcessor bp : getBeanPostProcessors()) {  if (bp instanceof InstantiationAwareBeanPostProcessor) {  InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;  //返回值为是否继续填充bean  if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {  continueWithPropertyPopulation = false;  break;  }  }  }  }  //如果后处理器发出停止填充命令则终止后续的执行  if (!continueWithPropertyPopulation) {  return;  }  if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME ||  mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {  MutablePropertyValues newPvs = new MutablePropertyValues(pvs);  // Add property values based on autowire by name if applicable.  //根据名称自动注入  if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME) {  autowireByName(beanName, mbd, bw, newPvs);  }  // Add property values based on autowire by type if applicable.  //根据类型自动注入  if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {  autowireByType(beanName, mbd, bw, newPvs);  }  pvs = newPvs;  }  //后处理器已经初始化  boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors();  //需要依赖检查  boolean needsDepCheck = (mbd.getDependencyCheck() != RootBeanDefinition.DEPENDENCY_CHECK_NONE);  if (hasInstAwareBpps || needsDepCheck) {  PropertyDescriptor[] filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);  if (hasInstAwareBpps) {  for (BeanPostProcessor bp : getBeanPostProcessors()) {  if (bp instanceof InstantiationAwareBeanPostProcessor) {  InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;  //对所有需要依赖检查的属性进行后处理  pvs = ibp.postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName);  if (pvs == null) {  return;  }  }  }  }  if (needsDepCheck) {  //依赖检查,对应depends-on属性,3.0已经弃用此属性  checkDependencies(beanName, mbd, filteredPds, pvs);  }  }  //将属性应用到bean中  //将所有ProtertyValues中的属性填充至BeanWrapper中。  applyPropertyValues(beanName, mbd, bw, pvs);  
} 

我们来分析下populateBean的流程:

(1)首先进行属性是否为空的判断

(2)通过调用InstantiationAwareBeanPostProcessor的postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)方法来控制程序是否继续进行属性填充

(3)根据注入类型(byName/byType)提取依赖的bean,并统一存入PropertyValues中

(4)应用InstantiationAwareBeanPostProcessor的postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName)方法,对属性获取完毕填充前的再次处理,典型的应用是RequiredAnnotationBeanPostProcesser类中对属性的验证

(5)将所有的PropertyValues中的属性填充至BeanWrapper中

上面步骤中有几个地方是我们比较感兴趣的,它们分别是依赖注入(autowireByName/autowireByType)以及属性填充,接下来进一步分析这几个功能的实现细节

分享一份大彬精心整理的大厂面试手册,包含计算机基础、Java基础、多线程、JVM、数据库、Redis、Spring、Mybatis、SpringMVC、SpringBoot、分布式、微服务、设计模式、架构、校招社招分享等高频面试题,非常实用,有小伙伴靠着这份手册拿过字节offer~

需要的小伙伴可以自行下载

http://mp.weixin.qq.com/s?__biz=Mzg2OTY1NzY0MQ==&mid=2247485445&idx=1&sn=1c6e224b9bb3da457f5ee03894493dbc&chksm=ce98f543f9ef7c55325e3bf336607a370935a6c78dbb68cf86e59f5d68f4c51d175365a189f8#rd

自动注入

Spring 会根据注入类型( byName / byType )的不同,调用不同的方法(autowireByName() / autowireByType())来注入属性值。

autowireByName()

protected void autowireByName(String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs) {// 获取 Bean 对象中非简单属性String[] propertyNames = unsatisfiedNonSimpleProperties(mbd, bw);for (String propertyName : propertyNames) {// 如果容器中包含指定名称的 bean,则将该 bean 注入到 bean中if (containsBean(propertyName)) {// 递归初始化相关 beanObject bean = getBean(propertyName);// 为指定名称的属性赋予属性值  pvs.add(propertyName, bean);// 属性依赖注入registerDependentBean(propertyName, beanName);if (logger.isDebugEnabled()) {logger.debug("Added autowiring by name from bean name '" + beanName +"' via property '" + propertyName + "' to bean named '" + propertyName + "'");}}else {if (logger.isTraceEnabled()) {logger.trace("Not autowiring property '" + propertyName + "' of bean '" + beanName +"' by name: no matching bean found");}}}
}

该方法逻辑很简单,获取该 bean 的非简单属性,什么叫做非简单属性呢?就是类型为对象类型的属性,但是这里并不是将所有的对象类型都都会找到,比如 8 个原始类型,String 类型 ,Number类型、Date类型、URL类型、URI类型等都会被忽略,如下:

protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {Set<String> result = new TreeSet<>();PropertyValues pvs = mbd.getPropertyValues();PropertyDescriptor[] pds = bw.getPropertyDescriptors();for (PropertyDescriptor pd : pds) {if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&!BeanUtils.isSimpleProperty(pd.getPropertyType())) {result.add(pd.getName());}}return StringUtils.toStringArray(result);
}

这里获取的就是需要依赖注入的属性。

autowireByName()函数的功能就是根据传入的参数中的pvs中找出已经加载的bean,并递归实例化,然后加入到pvs中

autowireByType

autowireByType与autowireByName对于我们理解与使用来说复杂程度相似,但是实现功能的复杂度却不一样,我们看下方法代码:

protected void autowireByType(  String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs) {  TypeConverter converter = getCustomTypeConverter();  if (converter == null) {  converter = bw;  }  Set<String> autowiredBeanNames = new LinkedHashSet<String>(4);  //寻找bw中需要依赖注入的属性  String[] propertyNames = unsatisfiedNonSimpleProperties(mbd, bw);  for (String propertyName : propertyNames) {  try {  PropertyDescriptor pd = bw.getPropertyDescriptor(propertyName);  // Don't try autowiring by type for type Object: never makes sense,  // even if it technically is a unsatisfied, non-simple property.  if (!Object.class.equals(pd.getPropertyType())) {  //探测指定属性的set方法  MethodParameter methodParam = BeanUtils.getWriteMethodParameter(pd);  // Do not allow eager init for type matching in case of a prioritized post-processor.  boolean eager = !PriorityOrdered.class.isAssignableFrom(bw.getWrappedClass());  DependencyDescriptor desc = new AutowireByTypeDependencyDescriptor(methodParam, eager);  //解析指定beanName的属性所匹配的值,并把解析到的属性名称存储在autowiredBeanNames中,  Object autowiredArgument = resolveDependency(desc, beanName, autowiredBeanNames, converter);  if (autowiredArgument != null) {  pvs.add(propertyName, autowiredArgument);  }  for (String autowiredBeanName : autowiredBeanNames) {  //注册依赖  registerDependentBean(autowiredBeanName, beanName);  if (logger.isDebugEnabled()) {  logger.debug("Autowiring by type from bean name '" + beanName + "' via property '" +  propertyName + "' to bean named '" + autowiredBeanName + "'");  }  }  autowiredBeanNames.clear();  }  }  catch (BeansException ex) {  throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, propertyName, ex);  }  }  
}

根据名称第一步与根据属性第一步都是寻找bw中需要依赖注入的属性,然后遍历这些属性并寻找类型匹配的bean,其中最复杂就是寻找类型匹配的bean。spring中提供了对集合的类型注入支持,如使用如下注解方式:

@Autowired
private List<Test> tests;

这种方式spring会把所有与Test匹配的类型找出来并注入到tests属性中,正是由于这一因素,所以在autowireByType函数,新建了局部遍历autowireBeanNames,用于存储所有依赖的bean,如果只是对非集合类的属性注入来说,此属性并无用处。

对于寻找类型匹配的逻辑实现是封装在了resolveDependency函数中,其实现如下:

public Object resolveDependency(DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());  if (descriptor.getDependencyType().equals(ObjectFactory.class)) {  //ObjectFactory类注入的特殊处理  return new DependencyObjectFactory(descriptor, beanName);  }  else if (descriptor.getDependencyType().equals(javaxInjectProviderClass)) {  //javaxInjectProviderClass类注入的特殊处理  return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);  }  else {  //通用处理逻辑  return doResolveDependency(descriptor, descriptor.getDependencyType(), beanName, autowiredBeanNames, typeConverter);  }  
}  protected Object doResolveDependency(DependencyDescriptor descriptor, Class<?> type, String beanName,  Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {  /* * 用于支持Spring中新增的注解@Value */  Object value = getAutowireCandidateResolver().getSuggestedValue(descriptor);  if (value != null) {  if (value instanceof String) {  String strVal = resolveEmbeddedValue((String) value);  BeanDefinition bd = (beanName != null && containsBean(beanName) ? getMergedBeanDefinition(beanName) : null);  value = evaluateBeanDefinitionString(strVal, bd);  }  TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());  return (descriptor.getField() != null ?  converter.convertIfNecessary(value, type, descriptor.getField()) :  converter.convertIfNecessary(value, type, descriptor.getMethodParameter()));  }  //如果解析器没有成功解析,则需要考虑各种情况  //属性是数组类型  if (type.isArray()) {  Class<?> componentType = type.getComponentType();  //根据属性类型找到beanFactory中所有类型的匹配bean,  //返回值的构成为:key=匹配的beanName,value=beanName对应的实例化后的bean(通过getBean(beanName)返回)  Map<String, Object> matchingBeans = findAutowireCandidates(beanName, componentType, descriptor);  if (matchingBeans.isEmpty()) {  //如果autowire的require属性为true而找到的匹配项却为空则只能抛出异常  if (descriptor.isRequired()) {  raiseNoSuchBeanDefinitionException(componentType, "array of " + componentType.getName(), descriptor);  }  return null;  }  if (autowiredBeanNames != null) {  autowiredBeanNames.addAll(matchingBeans.keySet());  }  TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());  //通过转换器将bean的值转换为对应的type类型  return converter.convertIfNecessary(matchingBeans.values(), type);  }  //属性是Collection类型  else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {  Class<?> elementType = descriptor.getCollectionType();  if (elementType == null) {  if (descriptor.isRequired()) {  throw new FatalBeanException("No element type declared for collection [" + type.getName() + "]");  }  return null;  }  Map<String, Object> matchingBeans = findAutowireCandidates(beanName, elementType, descriptor);  if (matchingBeans.isEmpty()) {  if (descriptor.isRequired()) {  raiseNoSuchBeanDefinitionException(elementType, "collection of " + elementType.getName(), descriptor);  }  return null;  }  if (autowiredBeanNames != null) {  autowiredBeanNames.addAll(matchingBeans.keySet());  }  TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());  return converter.convertIfNecessary(matchingBeans.values(), type);  }  //属性是Map类型  else if (Map.class.isAssignableFrom(type) && type.isInterface()) {  Class<?> keyType = descriptor.getMapKeyType();  if (keyType == null || !String.class.isAssignableFrom(keyType)) {  if (descriptor.isRequired()) {  throw new FatalBeanException("Key type [" + keyType + "] of map [" + type.getName() +  "] must be assignable to [java.lang.String]");  }  return null;  }  Class<?> valueType = descriptor.getMapValueType();  if (valueType == null) {  if (descriptor.isRequired()) {  throw new FatalBeanException("No value type declared for map [" + type.getName() + "]");  }  return null;  }  Map<String, Object> matchingBeans = findAutowireCandidates(beanName, valueType, descriptor);  if (matchingBeans.isEmpty()) {  if (descriptor.isRequired()) {  raiseNoSuchBeanDefinitionException(valueType, "map with value type " + valueType.getName(), descriptor);  }  return null;  }  if (autowiredBeanNames != null) {  autowiredBeanNames.addAll(matchingBeans.keySet());  }  return matchingBeans;  }  else {  Map<String, Object> matchingBeans = findAutowireCandidates(beanName, type, descriptor);  if (matchingBeans.isEmpty()) {  if (descriptor.isRequired()) {  raiseNoSuchBeanDefinitionException(type, "", descriptor);  }  return null;  }  if (matchingBeans.size() > 1) {  String primaryBeanName = determinePrimaryCandidate(matchingBeans, descriptor);  if (primaryBeanName == null) {  throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());  }  if (autowiredBeanNames != null) {  autowiredBeanNames.add(primaryBeanName);  }  return matchingBeans.get(primaryBeanName);  }  // We have exactly one match.  Map.Entry<String, Object> entry = matchingBeans.entrySet().iterator().next();  if (autowiredBeanNames != null) {  autowiredBeanNames.add(entry.getKey());  }  //已经确定只有一个匹配项  return entry.getValue();  }  
}

主要就是通过Type从BeanFactory中找到对应的benaName,然后通过getBean获取实例

protected Map<String, Object> findAutowireCandidates(@Nullable String beanName, Class<?> requiredType, DependencyDescriptor descriptor) {//在BeanFactory找到所有Type类型的beanNameString[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, requiredType, true, descriptor.isEager());Map<String, Object> result = new LinkedHashMap<>(candidateNames.length);//遍历所有的beanName,通过getBean获取for (String candidate : candidateNames) {if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) {//addCandidateEntry(result, candidate, descriptor, requiredType);}}return result;
}private void addCandidateEntry(Map<String, Object> candidates, String candidateName,DependencyDescriptor descriptor, Class<?> requiredType) {Object beanInstance = descriptor.resolveCandidate(candidateName, requiredType, this);if (!(beanInstance instanceof NullBean)) {candidates.put(candidateName, beanInstance);}
}public Object resolveCandidate(String beanName, Class<?> requiredType, BeanFactory beanFactory)throws BeansException {//通过类型找到beanName,然后再找到其实例return beanFactory.getBean(beanName);
}

applyPropertyValues

程序运行到这里,已经完成了对所有注入属性的获取,但是获取的属性是以PropertyValues形式存在的,还并没有应用到已经实例化的bean中,这一工作是在applyPropertyValues中。继续跟踪到方法体中:

protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) {  if (pvs == null || pvs.isEmpty()) {  return;  }  MutablePropertyValues mpvs = null;  List<PropertyValue> original;  if (System.getSecurityManager() != null) {  if (bw instanceof BeanWrapperImpl) {  ((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext());  }  }  if (pvs instanceof MutablePropertyValues) {  mpvs = (MutablePropertyValues) pvs;  //如果mpvs中的值已经被转换为对应的类型那么可以直接设置到beanwapper中  if (mpvs.isConverted()) {  // Shortcut: use the pre-converted values as-is.  try {  bw.setPropertyValues(mpvs);  return;  }  catch (BeansException ex) {  throw new BeanCreationException(  mbd.getResourceDescription(), beanName, "Error setting property values", ex);  }  }  original = mpvs.getPropertyValueList();  }  else {  //如果pvs并不是使用MutablePropertyValues封装的类型,那么直接使用原始的属性获取方法  original = Arrays.asList(pvs.getPropertyValues());  }  TypeConverter converter = getCustomTypeConverter();  if (converter == null) {  converter = bw;  }  //获取对应的解析器  BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter);  // Create a deep copy, resolving any references for values.  List<PropertyValue> deepCopy = new ArrayList<PropertyValue>(original.size());  boolean resolveNecessary = false;  //遍历属性,将属性转换为对应类的对应属性的类型  for (PropertyValue pv : original) {  if (pv.isConverted()) {  deepCopy.add(pv);  }  else {  String propertyName = pv.getName();  Object originalValue = pv.getValue();  Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue);  Object convertedValue = resolvedValue;  boolean convertible = bw.isWritableProperty(propertyName) &&  !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName);  if (convertible) {  convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);  }  // Possibly store converted value in merged bean definition,  // in order to avoid re-conversion for every created bean instance.  if (resolvedValue == originalValue) {  if (convertible) {  pv.setConvertedValue(convertedValue);  }  deepCopy.add(pv);  }  else if (convertible && originalValue instanceof TypedStringValue &&  !((TypedStringValue) originalValue).isDynamic() &&  !(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) {  pv.setConvertedValue(convertedValue);  deepCopy.add(pv);  }  else {  resolveNecessary = true;  deepCopy.add(new PropertyValue(pv, convertedValue));  }  }  }  if (mpvs != null && !resolveNecessary) {  mpvs.setConverted();  }  // Set our (possibly massaged) deep copy.  try {  bw.setPropertyValues(new MutablePropertyValues(deepCopy));  }  catch (BeansException ex) {  throw new BeanCreationException(  mbd.getResourceDescription(), beanName, "Error setting property values", ex);  }  
}

我们来看看具体的属性赋值过程

public class MyTestBean {private String name ;public MyTestBean(String name) {this.name = name;}public MyTestBean() {}public String getName() {return name;}public void setName(String name) {this.name = name;}
}<bean id="myTestBean"  class="dabin.spring01.MyTestBean"><property name="name" value="dabin"></property>
</bean>

如上 bw.setPropertyValues 最终都会走到如下方法

@Override
public void setValue(final @Nullable Object value) throws Exception {//获取writeMethod,也就是我们MyTestBean的setName方法final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :this.pd.getWriteMethod());if (System.getSecurityManager() != null) {AccessController.doPrivileged((PrivilegedAction<Object>) () -> {ReflectionUtils.makeAccessible(writeMethod);return null;});try {AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->writeMethod.invoke(getWrappedInstance(), value), acc);}catch (PrivilegedActionException ex) {throw ex.getException();}}else {ReflectionUtils.makeAccessible(writeMethod);//通过反射调用方法进行赋值writeMethod.invoke(getWrappedInstance(), value);}
}

就是利用反射进行调用对象的set方法赋值

至此,doCreateBean() 第二个过程:属性填充 已经分析完成了,下篇分析第三个过程:循环依赖的处理,其实循环依赖并不仅仅只是在 doCreateBean() 中处理,其实在整个加载 bean 的过程中都有涉及,所以下篇内容并不仅仅只局限于 doCreateBean()

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

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

相关文章

LVGL_基础控件checkbox

LVGL_基础控件checkbox 1、创建checkbox /* 创建一个 checkbox 部件(对象) */ lv_obj_t * cb lv_checkbox_create(lv_scr_act()); // 创建一个 switch 部件(对象),他的父对象是活动屏幕对象 lv_checkbox_set_text(cb, "100ASK LVGL Tutorial" LV_SYMBOL_PLAY);…

多功能频率计周期/脉宽/占空比/频率测量verilog,视频/代码

名称&#xff1a;多功能频率计周期、脉宽、占空比、频率测量verilog 软件&#xff1a;Quartus 语言&#xff1a;Verilog 代码功能&#xff1a; 多功能频率计&#xff0c;可测量信号的周期、脉冲宽度、占空比、频率&#xff0c;语言为verilog&#xff0c;quartus软件设计仿真…

tailscale自建headscale和derp中继

tailscale derp中继服务简介 tailscale是一个基于WireGuard的零配置软件&#xff0c;它可以轻松地在多台设备之间建立点对点加密连接。 derp服务器是tailscale网络的重要组成部分。它作为tailscale客户端之间的中继,帮助客户端找到并连接到其他客户端设备。 但Tailscale 官方…

华为云API自然语言处理的魅力—AI情感分析、文本分析

云服务、API、SDK&#xff0c;调试&#xff0c;查看&#xff0c;我都行 阅读短文您可以学习到&#xff1a;人工智能AI自言语言的情感分析、文本分词、文本翻译 1 IntelliJ IDEA 之API插件介绍 API插件支持 VS Code IDE、IntelliJ IDEA等平台、以及华为云自研 CodeArts IDE&a…

扭线机控制

扭线机属于线缆加工设备&#xff0c;线缆加工设备种类非常多。有用于网线绞合的单绞&#xff0c;双绞机等&#xff0c;有关单绞机相关算法介绍&#xff0c;大家可以查看专栏相关文章&#xff0c;有详细介绍&#xff0c;常用链接如下&#xff1a; 线缆行业单绞机控制算法&#…

电脑散热——液金散热

目录 1.简介 2.传统硅脂与液金导热区别 3.特点 4.优点 5.为什么液金技术名声不太好 6.使用方法 1.简介 凡是对于电脑基础硬件有所了解的人&#xff0c;都知道硅脂是如今高性能电脑设备中必不可少的东西。芯片表面和散热器接触面&#xff0c;虽然肉眼看上去是非常光滑的金属…

[VIM]spcaevim

Home | SpaceVim SpaceVim - 知乎 关于Vim/Neovim/SpaceVim的一些思考 - 知乎 vim高配版(1) – SpaceVim 简介 SpaceVim 是国内的一个大佬将一些NB的插件整合到一起的一个插件包. 一键式安装, 功能强大. 官网参见 Home | SpaceVim vim高配版(2) – vimplus 简介 vimplu…

正则验证用户名和跨域postmessage

正则验证用户名 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>登录</title> </head> <body> <input type"text" name"username" placeholder"用户名…

c语言动态内存分布

前言&#xff1a; 随着我们深入的学习c语言&#xff0c;之前使用的静态内存分配已经难以满足我们的实际需求。比如前面我们的通讯录功能的实现&#xff0c;如果只是静态内存分配&#xff0c;那么也就意味着程序开始的内存分配大小就是固定的&#xff0c;应该开多大的空间呢&am…

【力扣-每日一题】714. 买卖股票的最佳时机含手续费

class Solution { public:int maxProfit(vector<int>& prices, int fee) {//[i][0]-不持有 [i][1]-持有int mprices.size();vector<vector<int>> dp(m,vector<int>(2));dp[0][0]0; //初始状态dp[0][1]-prices[0];for(int i1;i<m;i){dp[i]…

TDengine+OpenVINO+AIxBoard,助力时序数据分类

时间序列数据分析在工业&#xff0c;能源&#xff0c;医疗&#xff0c;交通&#xff0c;金融&#xff0c;零售等多个领域都有广泛应用。其中时间序列数据分类是分析时序数据的常见任务之一。本文将通过一个具体的案例&#xff0c;介绍 Intel 团队如何使用 TDengine 作为基础软件…

react-antd 文件导入按钮增加一个加载状态

1、效果图实例: 2、部分代码 2.1 props : 2.2 handleChange、上传的文件检验 : construction中定义 construction(props) { super(props); this.state { loadingStaus: flase, loadingDisabled: flase, // 作用:按钮如果在加 载状态中&#xff0c;没…