讀取xml文件中的配置參數(shù)實(shí)例
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;
以上這篇讀取xml文件中的配置參數(shù)實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
基于spring-mvc.xml和application-context.xml的配置與深入理解
這篇文章主要介紹了spring-mvc.xml和application-context.xml的配置與深入解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08Java中實(shí)現(xiàn) SHA-256加密的兩種方式
這篇文章主要介紹了Java中實(shí)現(xiàn) SHA-256加密的兩種方式,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-01-01springboot整合vue項(xiàng)目(小試牛刀)
這篇文章主要介紹了springboot整合vue項(xiàng)目(小試牛刀),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09MyBatis 如何簡(jiǎn)化的 JDBC(思路詳解)
MyBatis 是一個(gè) 持久層 框架,用于 簡(jiǎn)化JDBC開發(fā),這篇文章主要介紹了MyBatis 如何簡(jiǎn)化的 JDBC(思路詳解),需要的朋友可以參考下2023-03-03Java設(shè)計(jì)模式之迭代模式(Iterator模式)介紹
這篇文章主要介紹了Java設(shè)計(jì)模式之迭代模式(Iterator模式)介紹,本文用一個(gè)老師點(diǎn)名的現(xiàn)象描述了迭代模式的使用,需要的朋友可以參考下2015-03-03Java設(shè)計(jì)模式中裝飾者模式應(yīng)用詳解
裝飾者模式:在不改變?cè)袑?duì)象的基礎(chǔ)之上,動(dòng)態(tài)的將功能附加到對(duì)象上,提供了繼承更有彈性的替代方案,也體現(xiàn)了開閉原則。本文將通過示例詳細(xì)講解一下裝飾者模式,需要的可以參考一下2022-11-11SpringBoot定時(shí)任務(wù)實(shí)現(xiàn)數(shù)據(jù)同步的方法
業(yè)務(wù)需求是,通過中臺(tái)調(diào)用api接口獲得,設(shè)備數(shù)據(jù),要求現(xiàn)實(shí)設(shè)備數(shù)據(jù)的同步,這篇文章主要介紹了SpringBoot定時(shí)任務(wù)實(shí)現(xiàn)數(shù)據(jù)同步的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08mybatis實(shí)現(xiàn)批量插入并返回主鍵(xml和注解兩種方法)
這篇文章主要介紹了mybatis實(shí)現(xiàn)批量插入并返回主鍵(xml和注解兩種方法),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12