iocconfig.java
来自「一个自制的DB framework,使用的配置方式新颖」· Java 代码 · 共 54 行
JAVA
54 行
package bits;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class IocConfig {
private String iocConfigName;
private String idName;
public IocConfig(String iocConfigName,String idName){
this.iocConfigName = iocConfigName;
this.idName = idName;
this.parseIoc();
}
public void parseIoc() {
try{
String filename = this.iocConfigName;
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(filename));
Element root=doc.getDocumentElement();
NodeList n1 = doc.getElementsByTagName("bean");
for (int i = 0; i < n1.getLength(); i++){
Element node = (Element) n1.item(i);
String id = getNodeValue("id",node);
if(id.equals(this.idName)){
String className = getNodeValue("class",node);
System.out.println(className);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public String getNodeValue(String nodeName, Element node)
{
NodeList MyList = node.getElementsByTagName(nodeName);
Node nodeTemp = MyList.item(0).getFirstChild();
String strValue = nodeTemp.getNodeValue();
return strValue;
}
public static void main(String args[]){
IocConfig ioc = new IocConfig("src\\bits\\beans.xml","c");
IocConfig ioc1 = new IocConfig("src\\bits\\beans.xml","a");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?