(转)使用jdk的xjc命令由schema文件生成相应的实体类

更新时间:2023-07-02 19:04:47 阅读: 评论:0

(转)使⽤jdk的xjc命令由schema⽂件⽣成相应的实体类背景:在webrvice的开发过程中涉及到这⼀知识点,⼜必要来学习⼀下。
1 根据编写的schema来⽣成对应的java实体
1.1 实战
xcj命令有schema⽂件⽣成实体类
1、使⽤⽅法
xjc fileName.xsd -d ⽣成java实体类的⽬录 -p ⽣成的包名衔接
2. eg: xjc catalog.xsd -d d: \test -p com.xjc.bean
xjc szfs.tws.biz.info.billchange.xsd -d E:\Work\直连接⼝改造\⽂档\接⼝\直连接⼝schema\info -p szfs.ity.info.billchange
xjc szfs.tws.biz.info.billchange.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="www.w3/2001/XMLSchema" xmlns="szfs.tws.info.billchange"
targetNamespace="szfs.tws.info.billchange" elementFormDefault="qualified">
<xs:element name="BillChange" type="BillChange" />
<xs:complexType name="BillChange">
<xs:quence>
<xs:element name="subdate" type="Exact8Text"/>
<xs:element name="outid" type="OutId"/>
<xs:element name="chgtype" type="chgtypeEnum" />
<xs:element name="corpno" type="OrgCode" />
<xs:element name="billperiod" type="Exact6NumericText" minOccurs="0"/>
<xs:element name="billno" type="Max32Text" />
<xs:element name="feeitem" type="Exact5Text" />
<xs:element name="currency" type="Exact3Text" />
<xs:element name="billmoney" type="Max13MoneyGt0Text" minOccurs="0"/>
<xs:element name="feemoney" type="Max13MoneyGe0Text" minOccurs="0"/>
<xs:element name="effectdate" type="Exact8Text" />
<xs:element name="duedate" type="Exact8Text" />
<xs:element name="custno" type="Max32Text" minOccurs="0"/>
<xs:element name="custname" type="Max60Text" minOccurs="0"/>
<xs:element name="tel" type="Max30Text" minOccurs="0"/>
<xs:element name="memo" type="Max127Text" minOccurs="0"/>
</xs:quence>
</xs:complexType>
<xs:simpleType name="OutId">
<xs:restriction ba="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="64"/>
<xs:pattern value="[a-zA-Z0-9_-]{1,64}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Exact6NumericText">
<xs:restriction ba="xs:string">
<xs:minLength value="6"/>
<xs:maxLength value="6"/>
<xs:pattern value="[0-9]{1,6}"/>
</xs:restriction>
北京遇到西雅图</xs:simpleType>
<xs:simpleType name="OrgCode">
<xs:restriction ba="xs:string">
<xs:minLength value="8" />
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Exact3Text">
<xs:restriction ba="xs:string">
<xs:minLength value="3"/>
<xs:maxLength value="3"/>
香菇猪肉包子</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Exact5Text">
<xs:restriction ba="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Exact8Text">
<xs:restriction ba="xs:string">
<xs:minLength value="8"/>
边城人物形象分析
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max13MoneyGe0Text">
<xs:restriction ba="xs:decimal">
<xs:fractionDigits value="2" />
<xs:totalDigits value="15" />
<xs:minInclusive value="0" />
<xs:pattern value="[0-9]{1,13}(\.[0-9]{1,2})?"></xs:pattern>        </xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max13MoneyGt0Text">
<xs:restriction ba="xs:decimal">
<xs:fractionDigits value="2" />
<xs:totalDigits value="15" />
<xs:minExclusive value="0" />
<xs:pattern value="[0-9]{1,13}(\.[0-9]{1,2})?"></xs:pattern>        </xs:restriction>
</xs:simpleType>
<xs:simpleType name="chgtypeEnum">
<xs:restriction ba="xs:string">
<xs:enumeration value="0"/>
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max8NumericText">
<xs:restriction ba="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="8"/>
<xs:pattern value="[0-9]{1,8}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max6NumericText">
<xs:restriction ba="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="6"/>
<xs:pattern value="[0-9]{1,6}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max30Text">
<xs:restriction ba="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="30"/>
<xs:pattern value="[0-9a-zA-Z_-]{1,30}"/>
双子
</xs:simpleType>
<xs:simpleType name="Max32Text">
<xs:restriction ba="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="32"/>
<xs:pattern value="[a-zA-Z0-9.,()/='+?!"%&*<>;@# -_]{1,32}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max60Text">
<xs:restriction ba="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="60"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max64Text">
<xs:restriction ba="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Max127Text">
<xs:restriction ba="xs:string">
<xs:minLength value="1" />
绿色家庭
<xs:maxLength value="127"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
View Code
BillChange.java:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 // See <a href="/xml/jaxb">/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2017.07.10 at 10:35:20 AM CST
//
package szfs.ity.info.billchange;
import java.math.BigDecimal;
l.bind.annotation.XmlAccessType;
l.bind.annotation.XmlAccessorType;
我心飞翔l.bind.annotation.XmlElement;
l.bind.annotation.XmlType;
/**
* <p>Java class for BillChange complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="BillChange">
*  <complexContent>
*    <restriction ba="{www.w3/2001/XMLSchema}anyType">
*      <quence>
*        <element name="subdate" type="{szfs.tws.info.billchange}Exact8Text"/>
*        <element name="outid" type="{szfs.tws.info.billchange}OutId"/>
*        <element name="chgtype" type="{szfs.tws.info.billchange}chgtypeEnum"/>
*        <element name="corpno" type="{szfs.tws.info.billchange}OrgCode"/>
*        <element name="billperiod" type="{szfs.tws.info.billchange}Exact6NumericText" minOccurs="0"/>
*        <element name="billno" type="{szfs.tws.info.billchange}Max32Text"/>
*        <element name="feeitem" type="{szfs.tws.info.billchange}Exact5Text"/>
*        <element name="currency" type="{szfs.tws.info.billchange}Exact3Text"/>
*        <element name="billmoney" type="{szfs.tws.info.billchange}Max13MoneyGt0Text" minOccurs="0"/>
*        <element name="feemoney" type="{szfs.tws.info.billchange}Max13MoneyGe0Text" minOccurs="0"/>
*        <element name="effectdate" type="{szfs.tws.info.billchange}Exact8Text"/>
*        <element name="duedate" type="{szfs.tws.info.billchange}Exact8Text"/>
*        <element name="custno" type="{szfs.tws.info.billchange}Max32Text" minOccurs="0"/>
*        <element name="custname" type="{szfs.tws.info.billchange}Max60Text" minOccurs="0"/>
*        <element name="tel" type="{szfs.tws.info.billchange}Max30Text" minOccurs="0"/>
*        <element name="memo" type="{szfs.tws.info.billchange}Max127Text" minOccurs="0"/>
*      </quence>
*  </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BillChange", propOrder = {
"subdate",
"outid",
"chgtype",
"corpno",
"billperiod",
"billno",
"feeitem",
"currency",
"billmoney",
"feemoney",
"effectdate",
"duedate",
"custno",
"custname",
"tel",
"memo"
})
public class BillChange {
@XmlElement(required = true)
protected String subdate;
@XmlElement(required = true)
protected String outid;
@XmlElement(required = true)
protected String chgtype;
@XmlElement(required = true)
protected String corpno;
protected String billperiod;
@XmlElement(required = true)
protected String billno;
@XmlElement(required = true)
protected String feeitem;
@XmlElement(required = true)
protected String currency;
protected BigDecimal billmoney;
protected BigDecimal feemoney;
@XmlElement(required = true)
protected String effectdate;
@XmlElement(required = true)
侃侃而谈的反义词
protected String duedate;
protected String custno;
protected String custname;
protected String tel;
protected String memo;
//省略get/t
1.2 扩展
⾸先确保计算机已经安装了jdk,且在环境变量中配置了jdk路径。
我的计算机安装的是1.7,就以这个为例吧!
1.进⼊dos窗⼝
1.指定某⼀个xsd⽂件⽣成指定名称的类
进⼊xsd⽂件所在⽬录,我的在D盘,所以我 D:进⼊D盘
然后开始执⾏下⾯语法(xxxxx.xsd 为要⽣成的xsd⽂件 xxxxx为⽬录)xjc xxxxx.xsd -p xxxxx.bean;
2.将所有的xsd⽂件⽣成,并指定⽣成⽬录
xjc *.xsd -p com.cpp.interconnection.bean
然后完毕后,⽬录和类已经全部⽣成,⼤功搞成。1

本文发布于:2023-07-02 19:04:47,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1064944.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:配置   涉及   计算机   安装   背景   香菇   边城
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图