xjc java_使用xjc将xml文件转换成javabean

本文介绍了如何将XML文件转换为JavaBean。首先将XML文件转化为XSD文件,然后通过命令行工具xjc在指定目录下生成JavaBean,最后演示了如何批量转换多个XSD文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先将xml文件转换xsd文件

原xml文件:Response.xml

0

abcd

xsd文件:Response.xsd

2.先指定一个目录存放该***.java    例:  D:\trang

cmd进入到该目录

xjc  Response.xsd   -p   Response.bean

e26ef59d363455e8461ca9f0de2ab943.png

生成的JavaBean如下:Response.java

//

// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2

// See http://java.sun.com/xml/jaxb

// Any modifications to this file will be lost upon recompilation of the source schema.

// Generated on: 2017.06.07 at 08:05:42 PM CST

//

package Response.bean;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.annotation.XmlType;

/**

*

Java class for anonymous complex type.

*

*

The following schema fragment specifies the expected content contained within this class.

*

**

*  

*    

*      

*        

*        

*      

*    

*  

*

*

*

*

*/

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = {

"code",

"message"

})

@XmlRootElement(name = "Response")

public classResponse {

@XmlElement(required = true)

protected String code;

@XmlElement(required = true)

protected String message;

/**

* Gets the value of the code property.

*

* @return

*     possible object is

*     {@link String }

*

*/

public String getCode() {

return code;

}

/**

* Sets the value of the code property.

*

* @param value

*     allowed object is

*     {@link String }

*

*/

public void setCode(String value) {

this.code = value;

}

/**

* Gets the value of the message property.

*

* @return

*     possible object is

*     {@link String }

*

*/

public String getMessage() {

return message;

}

/**

* Sets the value of the message property.

*

* @param value

*     allowed object is

*     {@link String }

*

*/

public void setMessage(String value) {

this.message = value;

}

}

3.将所有的xsd文件转换成javabean

xjc *.xsd -p  com.xyz..bean      (com.xyz..bean)为包名。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值