把如下的xml文件扔到tomcat/lib目录下 部署运行即可加载到
xml文件格式:
<?xml version="1.0" encoding="UTF-8"?>
<credit>
<!-- 流量值 -->
<trafficvalue>10</trafficvalue>
<!-- 流量值对应像素值 -->
<creditvalue>10000</creditvalue>
</credit>
Java代码:
String xmlFile = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"gzh_credit_setting.xml";//xml文件名
Document document = null;if(xmlFile!=null && !xmlFile.equals("")){
SAXReader reader = new SAXReader();
document = reader.read(new File(xmlFile));
Element credit1 = document.getRootElement();
Iterator it = credit1.elementIterator();
while (it.hasNext()) {
//获取xml根元素
//获取流量值
if(ele.getName().equals("trafficvalue")){
int trafficvalue = Integer.parseInt(ele.getText());
map.put("trafficvalue",trafficvalue);
}
//获取流量值对应的像素值
if(ele.getName().equals("creditvalue")){
int creditvalue = Integer.parseInt(ele.getText());
map.put("creditvalue",creditvalue);
}
}
}