国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Spring中怎么加載ResourceLoader接口資源

發(fā)布時(shí)間:2021-07-27 11:45 來(lái)源:億速云 閱讀:0 作者:Leah 欄目: 編程語(yǔ)言 歡迎投稿:712375056

本篇文章給大家分享的是有關(guān)Spring中怎么加載ResourceLoader接口資源,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習,希望大家閱讀完這篇文章后可以有所收獲,話(huà)不多說(shuō),跟著(zhù)小編一起來(lái)看看吧。

一 代碼

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");    // 獲取該資源的簡(jiǎn)單信息    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è)節點(diǎn)都是<書(shū)>節點(diǎn)      Element book = (Element)it.next();      List ll = book.elements();      // 遍歷<書(shū)>節點(diǎn)的全部子節點(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"?><計算機書(shū)籍列表>   <書(shū)>      <書(shū)名>瘋狂Java講義</書(shū)名>      <作者>李剛</作者>   </書(shū)>   <書(shū)>      <書(shū)名>瘋狂iOS講義</書(shū)名>      <作者>李剛</作者>   </書(shū)></計算機書(shū)籍列表>

三 配置文件

<?xml version="1.0" encoding="GBK"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://www.springframework.org/schema/beans"   xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"></beans>

四 測試結果

book.xmlfile [F:\Mybatis\spring\book.xml]

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

国产午夜精品无码| 99久久久无码国产精品免费砚床| 国产AV影片麻豆精品传媒| 久久精品亚洲精品无码| 婷婷成人基地| 狠狠色婷婷久久一区二区|