溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

java怎么讀取xml配置參數(shù)

發(fā)布時(shí)間:2021-08-03 10:36:51 來(lái)源:億速云 閱讀:180 作者:chen 欄目:編程語(yǔ)言

這篇文章主要介紹“java怎么讀取xml配置參數(shù)”,在日常操作中,相信很多人在java怎么讀取xml配置參數(shù)問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”java怎么讀取xml配置參數(shù)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

paras.xml文件

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">      <bean id="SysParam" class="com.wisoft.tysfrz.utils.SysParam">  <!--行政區(qū)劃代碼前臺(tái)顯示默認(rèn)值-->  <property name="zoneCode" value="36"></property>  <!--二代證讀卡器讀取照片存儲(chǔ)位置-->  <property name="sfzpicpath" value="d:\\"></property>  <!--保存身份證照片相對(duì)路徑-->  <property name="photoRealPath" value="r/project/imgs/photo/"></property> </bean></beans>

SysParam.java類文件

package com.wisoft.tysfrz.utils;/** * 系統(tǒng)配置參數(shù) *  * @author ZHENWENCAN * @date 2017年10月9日 下午1:09:48 */public class SysParam { //行政區(qū)劃代碼前臺(tái)顯示默認(rèn)值 private String zoneCode; //二代證讀卡器讀取照片存儲(chǔ)位置 private String sfzpicpath; //保存身份證照片相對(duì)路徑 private String photoRealPath; public String getZoneCode() { return zoneCode; } public void setZoneCode(String zoneCode) { this.zoneCode = zoneCode; } public String getSfzpicpath() { return sfzpicpath; } public void setSfzpicpath(String sfzpicpath) { this.sfzpicpath = sfzpicpath; } public String getPhotoRealPath() { return photoRealPath; } public void setPhotoRealPath(String photoRealPath) { this.photoRealPath = photoRealPath; }}

使用

private static ApplicationContext cpxac = new ClassPathXmlApplicationContext("tysfrz/spring/tysfrz_params.xml");private static SysParam sysparam = (SysParam) cpxac.getBean("SysParam"); String photorealpath = sysparam.getPhotoRealPath();

需要引用包

import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;

到此,關(guān)于“java怎么讀取xml配置參數(shù)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI