java schema类_使用Schemagen从java类变成schema

1.编写一个自己需要的java类

package com.soa.my.java2schema;

public class Product {

private static final long serialVersionUID=12345L;

private String name;

private int price;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getPrice() {

return price;

}

public void setPrice(int price) {

this.price = price;

}

public Product() {

super();

}

}

2.下载xjc工具,可以到下面的链接进行下载:

http://download.csdn.net/detail/u013998070/8569667

3.打开命令行,调整到xjc工具包的bin 目录

如果不清楚需要输入什么,可以直接输入Schemagen命令进行查看,如下

f2ba78ac92392dc3d4d891989ab0b0d8.png

4.在命令行输入相关指令,如下图

7f7dfc2123c7186933eaccde361e4e0c.png

5.生成的schema.xsd文件内容如下:

6.结果分析,从上面的schema中我们可以看出,该schema文件并没有命名空间;而且生成的是complexType

而不是element,要想改变该问文件的内容,则需要对product.java使用jaxb注解

productAnnoction.java如下

package com.soa.my.java2schema;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name="productAnnoaction1",namespace="my.soa.java2schema.com")

@XmlType(namespace="my.soa.java2schema.com")

public class ProductAnnoction {

private static final long serialVersionUID=12345L;

@XmlElement(defaultValue="gzy")

private String name;

private int price;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getPrice() {

return price;

}

public void setPrice(int price) {

this.price = price;

}

public ProductAnnoction() {

super();

}

}

运行命令行,生成的文件如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值