1. Spring 源碼:Spring 解析XML 配置文件,獲得 Bena 的定義信息

通過 Debug 運行 XmlBeanDefinitionReaderTests 類的 withFreshInputStream() 的方法,調試 Spring 解析 XML 配置文件,獲得 Bean 的定義。

大體流程可根據序號查看,xml 配置文件隨便看一眼,不用過多在意。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd"><beans><bean id="validEmptyWithDescription" class="org.springframework.beans.testfixture.beans.TestBean"><description>I have no properties and I'm happy without them.</description></bean><!--Check automatic creation of alias, to allow for names that are illegal as XML ids.--><bean id="aliased" class="  org.springframework.beans.testfixture.beans.TestBean  " name="myalias"><property name="name"><value>aliased</value></property></bean><alias name="aliased" alias="youralias"/><alias name="multiAliased" alias="alias3"/><bean id="multiAliased" class="org.springframework.beans.testfixture.beans.TestBean" name="alias1,alias2"><property name="name"><value>aliased</value></property></bean><alias name="multiAliased" alias="alias4"/><bean class="org.springframework.beans.testfixture.beans.TestBean" name="aliasWithoutId1,aliasWithoutId2,aliasWithoutId3"><property name="name"><value>aliased</value></property></bean><bean class="org.springframework.beans.testfixture.beans.TestBean"><property name="name"><null/></property></bean><bean class="org.springframework.beans.factory.xml.DummyReferencer"/><bean class="org.springframework.beans.factory.xml.DummyReferencer"/><bean class="org.springframework.beans.factory.xml.DummyReferencer"/><bean id="rod" class="org.springframework.beans.testfixture.beans.TestBean"><property name="name"><value><!-- a comment -->Rod</value></property><property name="age"><value>31</value></property><property name="spouse"><ref bean="father"/></property><property name="touchy"><value/></property></bean><bean id="roderick" parent="rod"><property name="name"><value>Roderick<!-- a comment --></value></property><!-- Should inherit age --></bean><bean id="kerry" class="org.springframework.beans.testfixture.beans.TestBean"><property name="name"><value>Ker<!-- a comment -->ry</value></property><property name="age"><value>34</value></property><property name="spouse"><ref bean="rod"/></property><property name="touchy"><value></value></property></bean><bean id="kathy" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype"><property name="name"><value>Kathy</value></property><property name="age"><value>28</value></property><property name="spouse"><ref bean="father"/></property></bean><bean id="typeMismatch" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype"><property name="name"><value>typeMismatch</value></property><property name="age"><value>34x</value></property><property name="spouse"><ref bean="rod"/></property></bean><!-- Test of lifecycle callbacks --><bean id="mustBeInitialized" class="org.springframework.beans.testfixture.beans.MustBeInitialized"/><bean id="lifecycle" class="org.springframework.beans.testfixture.beans.LifecycleBean"init-method="declaredInitMethod"><property name="initMethodDeclared"><value>true</value></property></bean><bean id="protectedLifecycle" class="org.springframework.beans.factory.xml.ProtectedLifecycleBean"init-method="declaredInitMethod"><property name="initMethodDeclared"><value>true</value></property></bean><!-- Factory beans are automatically treated differently --><bean id="singletonFactory"	class="org.springframework.beans.testfixture.beans.factory.DummyFactory"></bean><bean id="prototypeFactory"	class="org.springframework.beans.testfixture.beans.factory.DummyFactory"><property name="singleton"><value>false</value></property></bean><!-- Check that the circular reference resolution mechanism doesn't breakrepeated references to the same FactoryBean --><bean id="factoryReferencer" class="org.springframework.beans.factory.xml.DummyReferencer"><property name="testBean1"><ref bean="singletonFactory"/></property><property name="testBean2"><ref bean="singletonFactory"/></property><property name="dummyFactory"><ref bean="&amp;singletonFactory"/></property></bean><bean id="factoryReferencerWithConstructor" class="org.springframework.beans.factory.xml.DummyReferencer"><constructor-arg><ref bean="&amp;singletonFactory"/></constructor-arg><property name="testBean1"><ref bean="singletonFactory"/></property><property name="testBean2"><ref bean="singletonFactory"/></property></bean><!-- Check that the circular reference resolution mechanism doesn't breakprototype instantiation --><bean id="prototypeReferencer" class="org.springframework.beans.factory.xml.DummyReferencer" scope="prototype"><property name="testBean1"><ref bean="kathy"/></property><property name="testBean2"><ref bean="kathy"/></property></bean><bean id="listenerVeto" class="org.springframework.beans.testfixture.beans.TestBean"><property name="name"><value>listenerVeto</value></property><property name="age"><value>66</value></property></bean><bean id="validEmpty" class="org.springframework.beans.testfixture.beans.TestBean"/><bean id="commentsInValue" class="org.springframework.beans.testfixture.beans.TestBean"><property name="name"><value>this is<!-- don't mind me --> a <![CDATA[<!--comment-->]]></value></property></bean></beans>
	@Testpublic void withFreshInputStream() {// TODO 1.創建 SimpleBeanDefinitionRegistry 對象,提供注冊BeanDefinition功能SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();// TODO 2.獲取配置文件Resource resource = new ClassPathResource("test.xml", getClass());// TODO 3.創建 XmlBeanDefinitionReader 對象,提供讀取 XMl 文件中的 Bean 的定義信息;new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);// TODO 30.驗證 BeanDefinitions 信息;testBeanDefinitions(registry);System.out.println("success");}private void testBeanDefinitions(BeanDefinitionRegistry registry) {assertThat(registry.getBeanDefinitionCount()).isEqualTo(24);assertThat(registry.getBeanDefinitionNames().length).isEqualTo(24);assertThat(Arrays.asList(registry.getBeanDefinitionNames()).contains("rod")).isTrue();assertThat(Arrays.asList(registry.getBeanDefinitionNames()).contains("aliased")).isTrue();assertThat(registry.containsBeanDefinition("rod")).isTrue();assertThat(registry.containsBeanDefinition("aliased")).isTrue();assertThat(registry.getBeanDefinition("rod").getBeanClassName()).isEqualTo(TestBean.class.getName());assertThat(registry.getBeanDefinition("aliased").getBeanClassName()).isEqualTo(TestBean.class.getName());assertThat(registry.isAlias("youralias")).isTrue();String[] aliases = registry.getAliases("aliased");assertThat(aliases.length).isEqualTo(2);assertThat(ObjectUtils.containsElement(aliases, "myalias")).isTrue();assertThat(ObjectUtils.containsElement(aliases, "youralias")).isTrue();}
	/*** Load bean definitions from the specified XML file.* @param resource the resource descriptor for the XML file* @return the number of bean definitions found* @throws BeanDefinitionStoreException in case of loading or parsing errors** TODO XmlBeanDefinitionReader加載資源的入口方法*/@Overridepublic int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException {// TODO 4.將讀取的XML資源進行特殊的編碼處理return loadBeanDefinitions(new EncodedResource(resource));}
	/*** Load bean definitions from the specified XML file.* @param encodedResource the resource descriptor for the XML file,* allowing to specify an encoding to use for parsing the file* @return the number of bean definitions found* @throws BeanDefinitionStoreException in case of loading or parsing errors** TODO 這里載入XML形式Bean配置信息方法*/public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {Assert.notNull(encodedResource, "EncodedResource must not be null");if (logger.isTraceEnabled()) {logger.trace("Loading XML bean definitions from " + encodedResource);}Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get();if (!currentResources.add(encodedResource)) {throw new BeanDefinitionStoreException("Detected cyclic loading of " + encodedResource + " - check your import definitions!");}// TODO 5. 將資源文件轉為InputStream的I/O流try (InputStream inputStream = encodedResource.getResource().getInputStream()) { // TODO 只有是Closeable的子類才能這樣書寫,有點是系統會自動幫助我們關閉// TODO 從InputStream中得到XML的解析源InputSource inputSource = new InputSource(inputStream);if (encodedResource.getEncoding() != null) {inputSource.setEncoding(encodedResource.getEncoding());}// TODO 6.具體讀取過程return doLoadBeanDefinitions(inputSource, encodedResource.getResource());}catch (IOException ex) {throw new BeanDefinitionStoreException("IOException parsing XML document from " + encodedResource.getResource(), ex);}finally {// TODO 29. currentResources.remove(encodedResource);if (currentResources.isEmpty()) {this.resourcesCurrentlyBeingLoaded.remove();}}}
/*** Actually load bean definitions from the specified XML file.* @param inputSource the SAX InputSource to read from* @param resource the resource descriptor for the XML file* @return the number of bean definitions found* @throws BeanDefinitionStoreException in case of loading or parsing errors* @see #doLoadDocument* @see #registerBeanDefinitions***/protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource)throws BeanDefinitionStoreException {try {// TODO 7. 加載Bean配置信息,并轉換為文檔對象Document doc = doLoadDocument(inputSource, resource);// TODO 8. 對Bean定義進行解析int count = registerBeanDefinitions(doc, resource);if (logger.isDebugEnabled()) {logger.debug("Loaded " + count + " bean definitions from " + resource);}return count;}catch (BeanDefinitionStoreException ex) {throw ex;}catch (SAXParseException ex) {throw new XmlBeanDefinitionStoreException(resource.getDescription(),"Line " + ex.getLineNumber() + " in XML document from " + resource + " is invalid", ex);}catch (SAXException ex) {throw new XmlBeanDefinitionStoreException(resource.getDescription(),"XML document from " + resource + " is invalid", ex);}catch (ParserConfigurationException ex) {throw new BeanDefinitionStoreException(resource.getDescription(),"Parser configuration exception parsing XML from " + resource, ex);}catch (IOException ex) {throw new BeanDefinitionStoreException(resource.getDescription(),"IOException parsing XML document from " + resource, ex);}catch (Throwable ex) {throw new BeanDefinitionStoreException(resource.getDescription(),"Unexpected exception parsing XML document from " + resource, ex);}}
	/*** Register the bean definitions contained in the given DOM document.* Called by {@code loadBeanDefinitions}.* <p>Creates a new instance of the parser class and invokes* {@code registerBeanDefinitions} on it.* @param doc the DOM document* @param resource the resource descriptor (for context information)* @return the number of bean definitions found* @throws BeanDefinitionStoreException in case of parsing errors* @see #loadBeanDefinitions* @see #setDocumentReaderClass* @see BeanDefinitionDocumentReader#registerBeanDefinitions** TODO 按照Spring的Bean語義要求將Bean配置信息解析并轉換為內部數據結構**/public int registerBeanDefinitions(Document doc, Resource resource) throws BeanDefinitionStoreException {// TODO 9.得到BeanDefinitionDoucumentReader來對XML格式的BeanDefinition進行解析BeanDefinitionDocumentReader documentReader = createBeanDefinitionDocumentReader();// TODO 10.獲得容器中注冊的Bean數量int countBefore = getRegistry().getBeanDefinitionCount();// TODO 11. 解析過程的入口,這里使用了委派模式,BeanDefinitionDocumentReader只是一個接口// TODO 具體的解析過程由實現類DefaultBeanDefinitionDocumentReader完成documentReader.registerBeanDefinitions(doc, createReaderContext(resource));// TODO 28. 統計解析的Bean數量return getRegistry().getBeanDefinitionCount() - countBefore;}
	/*** This implementation parses bean definitions according to the "spring-beans" XSD* (or DTD, historically).* <p>Opens a DOM Document; then initializes the default settings* specified at the {@code <beans/>} level; then parses the contained bean definitions.** TODO 根據Spring DTD對Bean的定義規則解析Bean定義的文檔對象*/@Overridepublic void registerBeanDefinitions(Document doc, XmlReaderContext readerContext) {// TODO 獲得XML描述符this.readerContext = readerContext;// TODO 12. doc.getDocumentElement() 獲的Document根元素doRegisterBeanDefinitions(doc.getDocumentElement());}
/*** Register each bean definition within the given root {@code <beans/>} element.*/@SuppressWarnings("deprecation")  // for Environment.acceptsProfiles(String...)protected void doRegisterBeanDefinitions(Element root) {// Any nested <beans> elements will cause recursion in this method. In// order to propagate and preserve <beans> default-* attributes correctly,// keep track of the current (parent) delegate, which may be null. Create// the new (child) delegate with a reference to the parent for fallback purposes,// then ultimately reset this.delegate back to its original (parent) reference.// this behavior emulates a stack of delegates without actually necessitating one.// TODO 具體的解析過程由BeanDefinitionParserDelegate實現// TODO BeanDefinitionParserDelegate中定義了Spring Bean定義XML文件的各元素BeanDefinitionParserDelegate parent = this.delegate;this.delegate = createDelegate(getReaderContext(), root, parent);// TODO 校驗是否引入 beans schemaLocationif (this.delegate.isDefaultNamespace(root)) {String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);if (StringUtils.hasText(profileSpec)) {String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);// We cannot use Profiles.of(...) since profile expressions are not supported// in XML config. See SPR-12458 for details.if (!getReaderContext().getEnvironment().acceptsProfiles(specifiedProfiles)) {if (logger.isDebugEnabled()) {logger.debug("Skipped XML bean definition file due to specified profiles [" + profileSpec +"] not matching: " + getReaderContext().getResource());}return;}}}// TODO 在解析Bean定義之前,進行自定義解析,增強解析過程的可擴展性preProcessXml(root);// TODO 12.從文檔的根元素開始進行Bean定義的文檔對象的解析parseBeanDefinitions(root, this.delegate);// TODO 27.在解析Bean定義之后,進行自定義解析,增強解析過程的可擴展性postProcessXml(root);this.delegate = parent;}
	/*** Parse the elements at the root level in the document:* "import", "alias", "bean".* @param root the DOM root element of the document**	TODO 使用Spring的Bean規則從文檔的根元素開始Bean定義的文檔對象的解析*/protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {// TODO 13. Bean定義的文檔對象使用了Spring默認的XML命名空間if (delegate.isDefaultNamespace(root)) {// TODO 14. 獲取Bean定義的文檔對象根元素的所有子節點NodeList nl = root.getChildNodes();// TODO 此處是循環,忽略需要,需要是大體執行流程不是唯一for (int i = 0; i < nl.getLength(); i++) {Node node = nl.item(i);// TODO 15. 獲得的文檔節點是XML元素節點if (node instanceof Element ele) {// TODO 16. Bean定義的文檔的元素節點使用的是Spring默認的XML命名空間if (delegate.isDefaultNamespace(ele)) {// TODO 17. 使用Spring的Bean規則解析元素節點parseDefaultElement(ele, delegate);}else {// TODO 如果沒有使用Spring默認的XMl命名空間,則使用用戶自定義的規則解析元素節點delegate.parseCustomElement(ele);}}}}else {// TODO 如果沒有使用Spring默認的XMl命名空間,則使用用戶自定義的規則解析元素節點delegate.parseCustomElement(root);}}
	/*** TODO 使用Spring的Bean規則解析文檔元素節點* @param ele* @param delegate*/private void parseDefaultElement(Element ele, BeanDefinitionParserDelegate delegate) {// TODO 18.如果節點是<import>導入元素,進行導入元素解析if (delegate.nodeNameEquals(ele, IMPORT_ELEMENT)) {importBeanDefinitionResource(ele);}// TODO 19.如果節點是<alias>別名元素,進行別名解析else if (delegate.nodeNameEquals(ele, ALIAS_ELEMENT)) {processAliasRegistration(ele);}// TODO 20.如果節點是<bean>元素,則按照Spring的Bean規則解析元素else if (delegate.nodeNameEquals(ele, BEAN_ELEMENT)) {processBeanDefinition(ele, delegate);}// TODO 如果節點是<beans>元素,則按照Spring的Bean規則解析元素else if (delegate.nodeNameEquals(ele, NESTED_BEANS_ELEMENT)) {// recursedoRegisterBeanDefinitions(ele);}}
	/*** Process the given bean element, parsing the bean definition* and registering it with the registry.* TODO		解析Bean資源文檔對象的普通元素* TODO     示例:<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>*/protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);// TODO 21. BeanDefinitionHolder是對BeanDefinition的封裝,即Bean定義的封裝類// TODO 對文檔對象中<bean>元素的解析由BeanDefinitionParserDelegate實現// TODO BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);if (bdHolder != null) {bdHolder = delegate.decorateBeanDefinitionIfRequired(ele, bdHolder);try {// 22.Register the final decorated instance.BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry());}catch (BeanDefinitionStoreException ex) {getReaderContext().error("Failed to register bean definition with name '" +bdHolder.getBeanName() + "'", ele, ex);}// Send registration event.// TODO 26.在完成向Spring Ioc容器注冊解析得到的Bean定義之后,發送注冊事件getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));}}
	/*** Register the given bean definition with the given bean factory.* @param definitionHolder the bean definition including name and aliases* @param registry the bean factory to register with* @throws BeanDefinitionStoreException if registration failed** TODO 將解析的BeanDefinitionHole注冊到Spring Ioc容器*/public static void registerBeanDefinition(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry)throws BeanDefinitionStoreException {// Register bean definition under primary name.// TODO 獲取解析的beanDefinition的名稱String beanName = definitionHolder.getBeanName();// TODO 23.向Spring Ioc容器注冊BeanDefinitionregistry.registerBeanDefinition(beanName, definitionHolder.getBeanDefinition());// Register aliases for bean name, if any.// TODO 25.如果解析的BeanDefinition有別名,向Spring Ioc容器注冊別名String[] aliases = definitionHolder.getAliases();if (aliases != null) {for (String alias : aliases) {registry.registerAlias(beanName, alias);}}}
	/*** TODO 注冊 BeanDefinition 信息*/@Overridepublic void registerBeanDefinition(String beanName, BeanDefinition beanDefinition)throws BeanDefinitionStoreException {Assert.hasText(beanName, "'beanName' must not be empty");Assert.notNull(beanDefinition, "BeanDefinition must not be null");// TODO 24.存儲 BeanDefinition this.beanDefinitionMap.put(beanName, beanDefinition);}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/273532.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/273532.shtml
英文地址,請注明出處:http://en.pswp.cn/news/273532.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

c++ 讀取文件 最后一行讀取了兩次

用ifstream的eof()&#xff0c;竟然讀到文件最后了&#xff0c;判斷eof還為false。網上查找資料后&#xff0c;終于解決這個問題。 參照文件&#xff1a;http://tuhao.blogbus.com/logs/21306687.html 在使用C/C讀文件的時候&#xff0c;一定都使用過eof&#xff08;&#xff0…

java中的io系統詳解(轉)

Java 流在處理上分為字符流和字節流。字符流處理的單元為 2 個字節的 Unicode 字符&#xff0c;分別操作字符、字符數組或字符串&#xff0c;而字節流處理單元為 1 個字節&#xff0c;操作字節和字節數組。 Java 內用 Unicode 編碼存儲字符&#xff0c;字符流處理類負責將外部的…

js獲取字符串最后一個字符代碼

方法一&#xff1a;運用String對象下的charAt方法 charAt() 方法可返回指定位置的字符。 代碼如下 復制代碼 str.charAt(str.length – 1) 請注意&#xff0c;JavaScript 并沒有一種有別于字符串類型的字符數據類型&#xff0c;所以返回的字符是長度為 1 的字符串 方法二&#…

Unity3D Shader入門指南(二)

關于本系列 這是Unity3D Shader入門指南系列的第二篇&#xff0c;本系列面向的對象是新接觸Shader開發的Unity3D使用者&#xff0c;因為我本身自己也是Shader初學者&#xff0c;因此可能會存在錯誤或者疏漏&#xff0c;如果您在Shader開發上有所心得&#xff0c;很歡迎并懇請您…

JVM:如何分析線程堆棧

英文原文&#xff1a;JVM: How to analyze Thread Dump 在這篇文章里我將教會你如何分析JVM的線程堆棧以及如何從堆棧信息中找出問題的根因。在我看來線程堆棧分析技術是Java EE產品支持工程師所必須掌握的一門技術。在線程堆棧中存儲的信息&#xff0c;通常遠超出你的想象&…

一個工科研究生畢業后的職業規劃

http://blog.csdn.net/wojiushiwo987/article/details/8592359一個工科研究生畢業后的職業規劃 [wojiushiwo987個人感觸]:說的很誠懇&#xff0c;對于馬上面臨畢業的我很受用&#xff0c;很有啟發。有了好的職業生涯規劃&#xff0c;才有了前進的方向和動力&#xff0c;才能…

SQLSERVER中如何忽略索引提示

SQLSERVER中如何忽略索引提示 原文:SQLSERVER中如何忽略索引提示SQLSERVER中如何忽略索引提示 當我們想讓某條查詢語句利用某個索引的時候&#xff0c;我們一般會在查詢語句里加索引提示&#xff0c;就像這樣 SELECT id,name from TB with (index(IX_xttrace_bal)) where bal…

JavaScript——以簡單的方式理解閉包

閉包&#xff0c;在一開始接觸JavaScript的時候就聽說過。首先明確一點&#xff0c;它理解起來確實不復雜&#xff0c;而且它也非常好用。那我們去理解閉包之前&#xff0c;要有什么基礎呢&#xff1f;我個人認為最重要的便是作用域&#xff08;lexical scope&#xff09;&…

jquery實現二級聯動不與數據庫交互

<select id"pro" name"pro" style"width:90px;"></select> <select id"city" name"city" style"width: 90px"></select> $._cityInfo [{"n":"北京市","c"…

[016]轉--C++拷貝構造函數詳解

一. 什么是拷貝構造函數 首先對于普通類型的對象來說&#xff0c;它們之間的復制是很簡單的&#xff0c;例如&#xff1a; [c-sharp] view plaincopy int a 100; int b a; 而類對象與普通對象不同&#xff0c;類對象內部結構一般較為復雜&#xff0c;存在各種成員變量。下…

js中調用C標簽實現百度地圖

<script type"text/javascript"> //json數組 var jsonArray document.getElementById("restaurant").value; var map new BMap.Map("milkMap"); // 創建地圖實例 <c:forEach items"${restaurantlist}" var"…

jquery較驗組織機構編碼

//*************************組織機構碼較驗************************* function checkOrganizationCode() { var weight [3, 7, 9, 10, 5, 8, 4, 2]; var str 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ; var reg /^([0-9A-Z]){8}-[0-9|X]{1}$/; var organizationcode $("…

自定義GrildView實現單選功能

首先看實現功能截圖&#xff0c;這是一個自定義Dialog,并且里面內容由GrildView 綁定數據源&#xff0c;實現類似單選功能。 首先自定義Dialog&#xff0c;綁定數據源 自定義Dialog彈出框大小方法 最主要實現的就是點擊顏色切換的功能&#xff0c;默認GrildView的每一項都是藍色…

Java數字字符串如何轉化為數字數組

eg&#xff1a; String numberString "0123456789"; 如何轉化為&#xff1a;int[] digitArry new int[]{0,1,2,3,4,5,6,7,8,9}; 解決辦法&#xff1a; char[] digitNumberArray numberString.toCharArray(); int[] digitArry new int[digitString.toCharArray().l…

『重構--改善既有代碼的設計』讀書筆記----序

作為C的程序員&#xff0c;我從大學就開始不間斷的看書&#xff0c;看到如今上班&#xff0c;也始終堅持每天多多少少閱讀技術文章&#xff0c;書看的很多&#xff0c;但很難有一本書&#xff0c;能讓我去反復的翻閱。但唯獨『重構--改善既有代碼的設計』這本書讓我重復看了不下…

微信公共平臺接口開發--Java實現

Java微信實現&#xff0c;采用SpringMVC 架構&#xff0c;采用SAXReader解析XML RequestMapping(value"/extend") public class WeixinController { RequestMapping(value"/weixin") public ModelAndView weixin(HttpServletRequest request,HttpServlet…

最大權閉合圖hdu3996

定義&#xff1a;最大權閉合圖&#xff1a;是有向圖的一個點集&#xff0c;且該點集的所有出邊都指向該集合。即閉合圖內任意點的集合也在改閉合圖內&#xff0c;給每個點分配一個點權值Pu&#xff0c;最大權閉合圖就是使閉合圖的點權之和最大。 最小割建邊方式&#xff1a;源點…

非監督學習的單層網絡分析

這篇博客對應的是Andrew.Ng的那篇文章&#xff1a;An Analysis o f Single-Layer Networks in Unsupervised Feature Learning&#xff0c;文章的主要目的是討論receptive field size&#xff0c;number of hidden nodes&#xff0c; step-stride以及whitening在對卷積網絡模型…

Spring MVC 驗證碼

頁面 <% page language"java" import"java.util.*" pageEncoding"UTF-8"%> <% String path request.getContextPath(); String basePath request.getScheme()"://"request.getServerName()":"request.getServerP…

數據結構實驗之鏈表四:有序鏈表的歸并

數據結構實驗之鏈表四&#xff1a;有序鏈表的歸并 Time Limit: 1000MS Memory limit: 65536K 題目描述 分別輸入兩個有序的整數序列&#xff08;分別包含M和N個數據&#xff09;&#xff0c;建立兩個有序的單鏈表&#xff0c;將這兩個有序單鏈表合并成為一個大的有序單鏈表&…