本篇文章給大家分享的是有關(guān)Spring中怎么加載ResourceLoader接口資源,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
一 代碼
package lee;import org.springframework.context.*;import org.springframework.context.support.*;import org.springframework.core.io.Resource;import org.dom4j.*;import org.dom4j.io.*;import java.util.*;public class ResourceLoaderTest{ public static void main(String[] args) throws Exception { // 創(chuàng)建ApplicationContext實例// ApplicationContext ctx = new// ClassPathXmlApplicationContext("beans.xml"); ApplicationContext ctx = new FileSystemXmlApplicationContext("beans.xml"); Resource res = ctx.getResource("book.xml"); // 獲取該資源的簡單信息 System.out.println(res.getFilename()); System.out.println(res.getDescription()); // 創(chuàng)建基于SAX的dom4j解析器 SAXReader reader = new SAXReader(); Document doc = reader.read(res.getFile()); // 獲取根元素 Element el = doc.getRootElement(); List l = el.elements(); // 遍歷根元素的全部子元素 for (Iterator it = l.iterator();it.hasNext() ; ) { // 每個節(jié)點都是<書>節(jié)點 Element book = (Element)it.next(); List ll = book.elements(); // 遍歷<書>節(jié)點的全部子節(jié)點 for (Iterator it2 = ll.iterator();it2.hasNext() ; ) { Element eee = (Element)it2.next(); System.out.println(eee.getText()); } } }}
二 資源文件
<?xml version="1.0" encoding="GBK"?><計算機書籍列表> <書> <書名>瘋狂Java講義</書名> <作者>李剛</作者> </書> <書> <書名>瘋狂iOS講義</書名> <作者>李剛</作者> </書></計算機書籍列表>
三 配置文件
<?xml version="1.0" encoding="GBK"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/tupian/20230522/" xsi:schemaLocation="/tupian/20230522/ /tupian/20230522//spring-beans-4.0.xsd"></beans>
四 測試結(jié)果
book.xmlfile [F:\Mybatis\spring\book.xml]
以上就是Spring中怎么加載ResourceLoader接口資源,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站標(biāo)題:Spring中怎么加載ResourceLoader接口資源-創(chuàng)新互聯(lián)
URL標(biāo)題:http://aaarwkj.com/article46/ihjeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、網(wǎng)站改版、網(wǎng)頁設(shè)計公司、網(wǎng)站設(shè)計、標(biāo)簽優(yōu)化、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容