本篇文章給大家分享的是有關(guān)Spring中怎么加載ResourceLoader接口資源,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
成都創(chuàng)新互聯(lián)專注于中大型企業(yè)的成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計(jì)客戶近1000家,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開發(fā),在前進(jìn)的路上,與客戶一起成長!一 代碼
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實(shí)例// 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() ; ) { // 每個(gè)節(jié)點(diǎn)都是<書>節(jié)點(diǎn) Element book = (Element)it.next(); List ll = book.elements(); // 遍歷<書>節(jié)點(diǎn)的全部子節(jié)點(diǎn) for (Iterator it2 = ll.iterator();it2.hasNext() ; ) { Element eee = (Element)it2.next(); System.out.println(eee.getText()); } } }}
二 資源文件
<?xml version="1.0" encoding="GBK"?><計(jì)算機(jī)書籍列表> <書> <書名>瘋狂Java講義</書名> <作者>李剛</作者> </書> <書> <書名>瘋狂iOS講義</書名> <作者>李剛</作者> </書></計(jì)算機(jī)書籍列表>
三 配置文件
<?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接口資源,小編相信有部分知識點(diǎn)可能是我們?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://bm7419.com/article46/ihjeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、網(wǎng)站改版、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站設(shè)計(jì)、標(biāo)簽優(yōu)化、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容