溫馨提示×

溫馨提示×

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

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

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

發(fā)布時(shí)間:2021-05-25 16:34:31 來源:億速云 閱讀:372 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關(guān)怎么在java中讀取xml配置參數(shù),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

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ū)劃代碼前臺顯示默認(rèn)值-->
  <property name="zoneCode" value="36"></property>
  <!--二代證讀卡器讀取照片存儲位置-->
  <property name="sfzpicpath" value="d:\\"></property>
  <!--保存身份證照片相對路徑-->
  <property name="photoRealPath" value="r/project/imgs/photo/"></property>
 </bean>
</beans>

SysParam.java類文件

package com.wisoft.tysfrz.utils;

public class SysParam {
 //行政區(qū)劃代碼前臺顯示默認(rèn)值
 private String zoneCode;
 //二代證讀卡器讀取照片存儲位置
 private String sfzpicpath;
 //保存身份證照片相對路徑
 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;

java基本數(shù)據(jù)類型有哪些

Java的基本數(shù)據(jù)類型分為:1、整數(shù)類型,用來表示整數(shù)的數(shù)據(jù)類型。2、浮點(diǎn)類型,用來表示小數(shù)的數(shù)據(jù)類型。3、字符類型,字符類型的關(guān)鍵字是“char”。4、布爾類型,是表示邏輯值的基本數(shù)據(jù)類型。

看完上述內(nèi)容,你們對怎么在java中讀取xml配置參數(shù)有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

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

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

AI