web前端

位置:IT落伍者 >> web前端 >> 浏览文章

DOM、JDOM、DOM4J解析XML实例


发布日期:2018年12月26日
 
DOM、JDOM、DOM4J解析XML实例

<?xml version= encoding=GB standalone=no?><学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>王娟</姓名>

<年龄></年龄>

</学生>

</学生花名册>

<?xml version= encoding=GB standalone=no?><学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>王娟</姓名>

<年龄></年龄>

</学生>

</学生花名册>

数据模型Studentjava

[java] view plaincopyprint?

package comupcgriddom;

public class Student {

private String name;

private String sex;

private int age;

public String getName() {

return name;

}

public void setName(String name) {

thisname = name;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

thissex = sex;

}

public int getAge() {

return age;

}

public void setAge(int age) {

thisage = age;

}

}

package comupcgriddom;

public class Student {

private String name;

private String sex;

private int age;

public String getName() {

return name;

}

public void setName(String name) {

thisname = name;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

thissex = sex;

}

public int getAge() {

return age;

}

public void setAge(int age) {

thisage = age;

}

}

DOM方式解析xml文档示例程序

[java] view plaincopyprint?

package comupcgriddom;

import javaioFileOutputStream;

import javaioIOException;

import javaioOutputStreamWriter;

import javautilVector;

import javaxxmlparsersDocumentBuilder;

import javaxxmlparsersDocumentBuilderFactory;

import javaxxmlparsersParserConfigurationException;

import javaxxmltransformOutputKeys;

import javaxxmltransformTransformer;

import javaxxmltransformTransformerException;

import javaxxmltransformTransformerFactory;

import javaxxmltransformdomDOMSource;

import javaxxmltransformstreamStreamResult;

import orgwcdomDocument;

import orgwcdomElement;

import orgwcdomNodeList;

import orgwcdomText;

import orgxmlsaxSAXException;

/**

*

* @author shijin 原始DOM解析XML方式

*

*/

public class DOMTest {

public static void main(String[] args) throws ParserConfigurationException

SAXException IOException TransformerException {

DOMTest test = new DOMTest()

testdeleteElement(namexml

Vector<Student> stus = testchangeXMLToModel(namexml

for (Student stu : stus) {

Systemoutprint(stugetName() + + stugetSex() +

+ stugetAge() + \n

}

// 输出

// 李华 男

// 张三 男

testcreateDocument(namexml stus)

}

/**

* show 根据vector中的student对象创建xml文档

*

* @param filename

* 要创建的文档名

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

* @throws TransformerException

*/

public void createDocument(String filename Vector<Student> stus)

throws ParserConfigurationException SAXException IOException

TransformerException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 创建document对象

Document doc = buildernewDocument()

Element root = doccreateElement(学生花名册// 创建根元素

docappendChild(root)// 添加根元素

for (Student stu : stus) {

Element stuElement = doccreateElement(学生

stuElementsetAttribute(性别 stugetSex())

Element nameElement = doccreateElement(姓名

Text nameText = doccreateTextNode(stugetName())

nameElementappendChild(nameText)

Element ageElement = doccreateElement(年龄

Text ageText = doccreateTextNode(StringvalueOf(stugetAge()))

ageElementappendChild(ageText)

stuElementappendChild(nameElement)

stuElementappendChild(ageElement)

rootappendChild(stuElement)

}

FileOutputStream fos = new FileOutputStream(filename)

OutputStreamWriter ow = new OutputStreamWriter(fos)

// 保存xml文件

DOMSource doms = new DOMSource(doc)

// 创建结果输出流

StreamResult result = new StreamResult(ow)

// 得到转换工厂实例

TransformerFactory transFac = TransformerFactorynewInstance()

// 得到转换器实例

Transformer trans = transFacnewTransformer()

// 转化器设置输出文档的编码方式

transsetOutputProperty(OutputKeysENCODING GB

//设置支持缩进

transsetOutputProperty(OutputKeysINDENT yes

// 将文档源转换到结果输出流

transtransform(doms result)

}

/**

* show 读取指定XML文档并将其对象化

*

* @param filename

* @return 存储Student对象的vector

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

*/

public Vector<Student> changeXMLToModel(String filename)

throws ParserConfigurationException SAXException IOException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 解析xml文档获得document对象即DOM树

Document doc = builderparse(filename)

// 获取根节点

Element root = docgetDocumentElement()

// 获取根节点的子节点中名字为学生的节点列表

NodeList stuNodes = rootgetElementsByTagName(学生

Vector<Student> students = new Vector<Student>()

// 遍历<学生>节点

for (int i = ; i < stuNodesgetLength() i++) {

// 获取一个学生节点

Element stuNode = (Element) em(i)

// 创建一个学生对象

Student stu = new Student()

stusetSex(stuNodegetAttribute(性别))

// 获取<学生>节点的子节点中名字为姓名的节点列表

NodeList nameNodes = stuNodegetElementsByTagName(姓名

// 取得第一个姓名

Element nameNode = (Element) em(

stusetName(nameNodegetTextContent())

// 获取<学生>节点的子节点中名字为年龄的节点列表

NodeList ageNodes = stuNodegetElementsByTagName(年龄

// 取得第一个年龄

Element ageNode = (Element) em(

stusetAge(IntegerparseInt(ageNodegetTextContent()))

studentsadd(stu)

}

return students;

}

/**

* show 删除指定名为filename的xml文档中学生结点的性别属性为tagname的结点

*

* @param filename

* @param tagname

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

* @throws TransformerException

*/

public void deleteElement(String filename String tagname)

throws ParserConfigurationException SAXException IOException

TransformerException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 解析xml文档获得document对象即DOM树

Document doc = builderparse(filename)

// 找到删除节点

NodeList stuNodes = docgetElementsByTagName(学生

for (int i = ; i < stuNodesgetLength() i++) {

Element stuElement = (Element) em(i)

String sex = stuElementgetAttribute(性别

if (sexequals(tagname)) {

stuElementgetParentNode()removeChild(stuElement)

}

}

// 保存xml文件

DOMSource doms = new DOMSource(doc)

// 创建结果输出流

StreamResult result = new StreamResult(new FileOutputStream(filename))

// 得到转换工厂实例

TransformerFactory transFac = TransformerFactorynewInstance()

// 得到转换器实例

Transformer trans = transFacnewTransformer()

// 转化器设置输出文档的编码方式

transsetOutputProperty(OutputKeysENCODING GB

// 将文档源转换到结果输出流

transtransform(doms result)

}

}

package comupcgriddom;

import javaioFileOutputStream;

import javaioIOException;

import javaioOutputStreamWriter;

import javautilVector;

import javaxxmlparsersDocumentBuilder;

import javaxxmlparsersDocumentBuilderFactory;

import javaxxmlparsersParserConfigurationException;

import javaxxmltransformOutputKeys;

import javaxxmltransformTransformer;

import javaxxmltransformTransformerException;

import javaxxmltransformTransformerFactory;

import javaxxmltransformdomDOMSource;

import javaxxmltransformstreamStreamResult;

import orgwcdomDocument;

import orgwcdomElement;

import orgwcdomNodeList;

import orgwcdomText;

import orgxmlsaxSAXException;

/**

*

* @author shijin 原始DOM解析XML方式

*

*/

public class DOMTest {

public static void main(String[] args) throws ParserConfigurationException

SAXException IOException TransformerException {

DOMTest test = new DOMTest()

testdeleteElement(namexml

Vector<Student> stus = testchangeXMLToModel(namexml

for (Student stu : stus) {

Systemoutprint(stugetName() + + stugetSex() +

+ stugetAge() + \n

}

// 输出

// 李华 男

// 张三 男

testcreateDocument(namexml stus)

}

/**

* show 根据vector中的student对象创建xml文档

*

* @param filename

* 要创建的文档名

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

* @throws TransformerException

*/

public void createDocument(String filename Vector<Student> stus)

throws ParserConfigurationException SAXException IOException

TransformerException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 创建document对象

Document doc = buildernewDocument()

Element root = doccreateElement(学生花名册// 创建根元素

docappendChild(root)// 添加根元素

for (Student stu : stus) {

Element stuElement = doccreateElement(学生

stuElementsetAttribute(性别 stugetSex())

Element nameElement = doccreateElement(姓名

Text nameText = doccreateTextNode(stugetName())

nameElementappendChild(nameText)

Element ageElement = doccreateElement(年龄

Text ageText = doccreateTextNode(StringvalueOf(stugetAge()))

ageElementappendChild(ageText)

stuElementappendChild(nameElement)

stuElementappendChild(ageElement)

rootappendChild(stuElement)

}

FileOutputStream fos = new FileOutputStream(filename)

OutputStreamWriter ow = new OutputStreamWriter(fos)

// 保存xml文件

DOMSource doms = new DOMSource(doc)

// 创建结果输出流

StreamResult result = new StreamResult(ow)

// 得到转换工厂实例

TransformerFactory transFac = TransformerFactorynewInstance()

// 得到转换器实例

Transformer trans = transFacnewTransformer()

// 转化器设置输出文档的编码方式

transsetOutputProperty(OutputKeysENCODING GB

//设置支持缩进

transsetOutputProperty(OutputKeysINDENT yes

// 将文档源转换到结果输出流

transtransform(doms result)

}

/**

* show 读取指定XML文档并将其对象化

*

* @param filename

* @return 存储Student对象的vector

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

*/

public Vector<Student> changeXMLToModel(String filename)

throws ParserConfigurationException SAXException IOException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 解析xml文档获得document对象即DOM树

Document doc = builderparse(filename)

// 获取根节点

Element root = docgetDocumentElement()

// 获取根节点的子节点中名字为学生的节点列表

NodeList stuNodes = rootgetElementsByTagName(学生

Vector<Student> students = new Vector<Student>()

// 遍历<学生>节点

for (int i = ; i < stuNodesgetLength() i++) {

// 获取一个学生节点

Element stuNode = (Element) em(i)

// 创建一个学生对象

Student stu = new Student()

stusetSex(stuNodegetAttribute(性别))

// 获取<学生>节点的子节点中名字为姓名的节点列表

NodeList nameNodes = stuNodegetElementsByTagName(姓名

// 取得第一个姓名

Element nameNode = (Element) em(

stusetName(nameNodegetTextContent())

// 获取<学生>节点的子节点中名字为年龄的节点列表

NodeList ageNodes = stuNodegetElementsByTagName(年龄

// 取得第一个年龄

Element ageNode = (Element) em(

stusetAge(IntegerparseInt(ageNodegetTextContent()))

studentsadd(stu)

}

return students;

}

/**

* show 删除指定名为filename的xml文档中学生结点的性别属性为tagname的结点

*

* @param filename

* @param tagname

* @throws ParserConfigurationException

* @throws SAXException

* @throws IOException

* @throws TransformerException

*/

public void deleteElement(String filename String tagname)

throws ParserConfigurationException SAXException IOException

TransformerException {

// 得到DOM解析器的工厂实例

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance()

// 从DOM工厂获取DOM解析器

DocumentBuilder builder = dbfnewDocumentBuilder()

// 解析xml文档获得document对象即DOM树

Document doc = builderparse(filename)

// 找到删除节点

NodeList stuNodes = docgetElementsByTagName(学生

for (int i = ; i < stuNodesgetLength() i++) {

Element stuElement = (Element) em(i)

String sex = stuElementgetAttribute(性别

if (sexequals(tagname)) {

stuElementgetParentNode()removeChild(stuElement)

}

}

// 保存xml文件

DOMSource doms = new DOMSource(doc)

// 创建结果输出流

StreamResult result = new StreamResult(new FileOutputStream(filename))

// 得到转换工厂实例

TransformerFactory transFac = TransformerFactorynewInstance()

// 得到转换器实例

Transformer trans = transFacnewTransformer()

// 转化器设置输出文档的编码方式

transsetOutputProperty(OutputKeysENCODING GB

// 将文档源转换到结果输出流

transtransform(doms result)

}

}

输出

李华 男

张三 男

结果namexml

[java] view plaincopyprint?

<?xml version= encoding=GB standalone=no?><学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

</学生花名册>

<?xml version= encoding=GB standalone=no?><学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

</学生花名册>

namexml

[java] view plaincopyprint?

<?xml version= encoding=GB standalone=no?>

<学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

</学生花名册>

<?xml version= encoding=GB standalone=no?>

<学生花名册>

<学生 性别=>

<姓名>李华</姓名>

<年龄></年龄>

</学生>

<学生 性别=>

<姓名>张三</姓名>

<年龄></年龄>

</学生>

</学生花名册>

JDOM方式

HDxml

[html] view plaincopyprint?

<?xml version= encoding=UTF?>

<HD>

<disk name=C>

<capacity>G</capacity>

<directories></directories>

<files></files>

</disk>

<disk name=D>

<capacity>G</capacity>

<directories></directories>

<files></files>

</disk>

</HD>

<?xml version= encoding=UTF?>

<HD>

<disk name=C>

<capacity>G</capacity>

<directories></directories>

<files></files>

</disk>

<disk name=D>

<capacity>G</capacity>

<directories></directories>

<files></files>

</disk>

</HD>

JDOM解析XML文档示例

[html] view plaincopyprint?

package comupcgridjdom;

import javaioIOException;

import javautilList;

import orgjdomDocument;

import orgjdomElement;

import orgjdomJDOMException;

import orgjdominputSAXBuilder;

public class JDOMTest {

public static void main(String[] args) throws JDOMException IOException {

// 获得JDOM以SAX方式处理XML文档的构造器

SAXBuilder saxb = new SAXBuilder()

// 通过SAX构造器获得XML文档对象

Document doc = saxbbuild(JDOMTestclassgetClassLoader()

getResourceAsStream(testxml))

// 获取根元素HD

Element root = docgetRootElement()

// 取名字为disk的所有元素

List<Element> list = rootgetChildren(disk

for (int i = ; i < listsize() i++) {

//取得第i个disk节点

Element diskElement = (Element) listget(i)

//取得disk属性name

String name = diskElementgetAttributeValue(name

// 取disk子元素capacity的内容

String capacity = diskElementgetChildText(capacity

String directories = diskElementgetChildText(directories

String files = diskElementgetChildText(files

Systemoutprintln(磁盘信息

Systemoutprintln(分区盘符 + name)

Systemoutprintln(分区容量 + capacity)

Systemoutprintln(目录数 + directories)

Systemoutprintln(文件数 + files)

Systemoutprintln(

}

}

}

package comupcgridjdom;

import javaioIOException;

import javautilList;

import orgjdomDocument;

import orgjdomElement;

import orgjdomJDOMException;

import orgjdominputSAXBuilder;

public class JDOMTest {

public static void main(String[] args) throws JDOMException IOException {

// 获得JDOM以SAX方式处理XML文档的构造器

SAXBuilder saxb = new SAXBuilder()

// 通过SAX构造器获得XML文档对象

Document doc = saxbbuild(JDOMTestclassgetClassLoader()

getResourceAsStream(testxml))

// 获取根元素HD

Element root = docgetRootElement()

// 取名字为disk的所有元素

List<Element> list = rootgetChildren(disk

for (int i = ; i < listsize() i++) {

//取得第i个disk节点

Element diskElement = (Element) listget(i)

//取得disk属性name

String name = diskElementgetAttributeValue(name

// 取disk子元素capacity的内容

String capacity = diskElementgetChildText(capacity

String directories = diskElementgetChildText(directories

String files = diskElementgetChildText(files

Systemoutprintln(磁盘信息

Systemoutprintln(分区盘符 + name)

Systemoutprintln(分区容量 + capacity)

Systemoutprintln(目录数 + directories)

Systemoutprintln(文件数 + files)

Systemoutprintln(

}

}

}

输出结果

磁盘信息

分区盘符C

分区容量G

目录数

文件数

磁盘信息

分区盘符D

分区容量G

目录数

文件数

DOMJ方式

Userhbmxml

[html] view plaincopyprint?

<?xml version= encoding=UTF?>

<hibernatemapping>

<class name=comupcgridUser table=t_user>

<property name=username>aaa</property>

<property name=password>bbb</property>

</class》

</hibernatemapping>

<?xml version= encoding=UTF?>

<hibernatemapping>

<class name=comupcgridUser table=t_user>

<property name=username>aaa</property>

<property name=password>bbb</property>

</class》

</hibernatemapping>

DOMJ解析XML示例

[java] view plaincopyprint?

package comupcgriddomj;

import javaioFile;

import javaioFileWriter;

import javaioIOException;

import javautilIterator;

import javautilList;

import orgdomjAttribute;

import orgdomjDocument;

import orgdomjDocumentException;

import orgdomjDocumentHelper;

import orgdomjElement;

import orgdomjNode;

import orgdomjioOutputFormat;

import orgdomjioSAXReader;

import orgdomjioXMLWriter;

public class DOMJTest {

public static void main(String[] args) {

//获得DOMJ以SAX方式处理XML文档的管道

SAXReader reader = new SAXReader()

try {

//通过管道获得XML文档对象

Document document = readerread(new File(Userhbmxml))

//获取根节点

Element root = documentgetRootElement()

Systemoutprintln(rootgetName())

Element element = null;

//遍历根节点下的节点

for(Iterator<Element> i = rootelementIterator()ihasNext()){

//根节点的子节点

element = (Element) inext()

Systemoutprintln(elementgetName())

//遍历节点属性

for(Iterator<Attribute> j = elementattributeIterator()jhasNext()){

Attribute attr = (Attribute)jnext()

Systemoutprintln(attrgetName()+:+attrgetValue())

}

//遍历名为property的节点

for(Iterator<Element> k = elementelementIterator(propertykhasNext()){

Element e = (Element)knext()

Systemoutprintln(egetData())

}

}

//通过Xpath的方式寻找节点

List<Node> list = documentselectNodes(//hibernatemapping/class/property

for(Node n: list){

String name = nvalueOf(@name

Systemoutprintln(ngetName()+ @name:+name)

}

//只拿第一个

Node node = documentselectSingleNode(//hibernatemapping/class

String name = nodevalueOf(@name

String table = nodevalueOf(@table

Systemoutprintln(nodegetName()+ @name:+name+@table:+table)

createDocument()

} catch (DocumentException e) {

eprintStackTrace()

}

}

public static Document createDocument(){

//创建document对象

Document document = DocumentHelpercreateDocument()

Element root = documentaddElement(hibernatemapping

//链式编程

Element classElement = rootaddElement(class

addAttribute(name comupcgridUser

addAttribute(table t_user

classElementaddElement(propertyaddAttribute(name usernameaddText(aaa

classElementaddElement(PropertyaddAttribute(name passwordaddText(bbb

try {

FileWriter out = new FileWriter(Userhbmxml

documentwrite(out)

outflush()

outclose()

} catch (IOException e) {

eprintStackTrace()

}

try {

//设定美化格式

OutputFormat format = OutputFormatcreatePrettyPrint()

XMLWriter writer = new XMLWriter(new FileWriter(Userhbmxmlformat)

writerwrite(document)

writerclose()

//缩减格式

} catch (IOException e) {

eprintStackTrace()

}

return document;

}

}

package comupcgriddomj;

import javaioFile;

import javaioFileWriter;

import javaioIOException;

import javautilIterator;

import javautilList;

import orgdomjAttribute;

import orgdomjDocument;

import orgdomjDocumentException;

import orgdomjDocumentHelper;

import orgdomjElement;

import orgdomjNode;

import orgdomjioOutputFormat;

import orgdomjioSAXReader;

import orgdomjioXMLWriter;

public class DOMJTest {

public static void main(String[] args) {

//获得DOMJ以SAX方式处理XML文档的管道

SAXReader reader = new SAXReader()

try {

//通过管道获得XML文档对象

Document document = readerread(new File(Userhbmxml))

//获取根节点

Element root = documentgetRootElement()

Systemoutprintln(rootgetName())

Element element = null;

//遍历根节点下的节点

for(Iterator<Element> i = rootelementIterator()ihasNext()){

//根节点的子节点

element = (Element) inext()

Systemoutprintln(elementgetName())

//遍历节点属性

for(Iterator<Attribute> j = elementattributeIterator()jhasNext()){

Attribute attr = (Attribute)jnext()

Systemoutprintln(attrgetName()+:+attrgetValue())

}

//遍历名为property的节点

for(Iterator<Element> k = elementelementIterator(propertykhasNext()){

Element e = (Element)knext()

Systemoutprintln(egetData())

}

}

//通过Xpath的方式寻找节点

List<Node> list = documentselectNodes(//hibernatemapping/class/property

for(Node n: list){

String name = nvalueOf(@name

Systemoutprintln(ngetName()+ @name:+name)

}

//只拿第一个

Node node = documentselectSingleNode(//hibernatemapping/class

String name = nodevalueOf(@name

String table = nodevalueOf(@table

Systemoutprintln(nodegetName()+ @name:+name+@table:+table)

createDocument()

} catch (DocumentException e) {

eprintStackTrace()

}

}

public static Document createDocument(){

//创建document对象

Document document = DocumentHelpercreateDocument()

Element root = documentaddElement(hibernatemapping

//链式编程

Element classElement = rootaddElement(class

addAttribute(name comupcgridUser

addAttribute(table t_user

classElementaddElement(propertyaddAttribute(name usernameaddText(aaa

classElementaddElement(PropertyaddAttribute(name passwordaddText(bbb

try {

FileWriter out = new FileWriter(Userhbmxml

documentwrite(out)

outflush()

outclose()

} catch (IOException e) {

eprintStackTrace()

}

try {

//设定美化格式

OutputFormat format = OutputFormatcreatePrettyPrint()

XMLWriter writer = new XMLWriter(new FileWriter(Userhbmxmlformat)

writerwrite(document)

writerclose()

//缩减格式

} catch (IOException e) {

eprintStackTrace()

}

return document;

}

}

输出

hibernatemapping

class

name:comupcgridUser

table:t_user

aaa

bbb

property @name:username

property @name:password

class @name:comupcgridUser@table:t_user

Userhbmxml

[html] view plaincopyprint?

<?xml version= encoding=UTF?>

<hibernatemapping><class name=comupcgridUser table=t_user><property name=username>aaa</property><Property name=password>bbb</Property></class></hibernatemapping>

<?xml version= encoding=UTF?>

<hibernatemapping><class name=comupcgridUser table=t_user><property name=username>aaa</property><Property name=password>bbb</Property></class></hibernatemapping>

Userhbmxml

[html] view plaincopyprint?

<?xml version= encoding=UTF?>

<hibernatemapping>

<class name=comupcgridUser table=t_user>

<property name=username>aaa</property>

<Property name=password>bbb</Property>

</class>

</hibernatemapping>

               

上一篇:在WEB容器中获取持久化上下文

下一篇:Apusic AS的Web应用中调用commons-loggi