如何从XSD创建pojo类? [英] How to create pojo classes from XSD?

查看:109
本文介绍了如何从XSD创建pojo类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Maven插件,我想从特定文件夹中的指定xml模式创建POJO类.我尝试通过Java代码使用xjc命令,但未生成该类.其次,我尝试使用jaxb,但是在处理marshell/unmarshelling时,它处理xml文件而不是xsd模式.我认为这不是从xsd创建POJO的方法.

I am using Spring maven plugin, I want to create POJO classes from specified xml schema in particular folder. I tried with xjc command through java code, but its not generating that classes. secondly, I tried with jaxb, but its dealing with xml file not a xsd schema while marshell/unmarshelling. I think this not a way to create POJO from xsd.

在Java中从xsd生成类的正确方法是什么?

What is a correct way to generate classes from xsd in java?

下面是XSD

   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="Employee">
   <xs:complexType>
   <xs:sequence>
    <xs:element name="empId" type="xs:long"/>
    <xs:element name="lastName" type="xs:string"/>
    <xs:element name="title" type="xs:string"/>
    <xs:element name="salary" type="xs:integer"/>
    <xs:element name="address">
    <xs:complexType>
       <xs:sequence>
         <xs:element name="city" type="xs:string"/>
         <xs:element name="street" type="xs:string"/>
         <xs:element name="zipcode" type="xs:integer"/>
         <xs:element name="privatePhoneNo">
           <xs:complexType>
             <xs:sequence>
                 <xs:element name="privateMobile" type="xs:string"/>
                 <xs:element name="privateLandline" type="xs:string"/>
             </xs:sequence>
           </xs:complexType>
         </xs:element>
        </xs:sequence>
     </xs:complexType>
    </xs:element>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 </xs:schema>

推荐答案

我的建议是选择JAXB.

我已经在eclipse中对其进行了测试,对我来说效果很好.我的建议是尝试从command line或在eclipse的帮助下生成POJO.成功后,用maven对其进行配置以生成POJO build time.

I have tested it in eclipse, works well for me. My suggestion is try generating the POJO from command line or with the help of eclipse. Once successful configure it with maven to generate the POJO build time.

有一些教程可以学习此内容,请根据您的喜好点击以下链接:

There are several tutorials to learn this, please follow the below link(s) based upon your preference:

  • Generate POJO Class from XSD in Eclipse
  • Generate POJO class from XSD Schema command line
  • Generate POJO Classes from XSD using XJC Maven Plugin

还有youtube链接:

Also the youtube links:

  • Youtube video tutorial
  • Youtube tutorial using maven

希望对您有帮助!

如果遇到任何问题,请随时发表评论.

Feel free to comment if you encounter any issue.

这篇关于如何从XSD创建pojo类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆