Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 关于JAXB2.x SchemaGen的问题_Java_Xsd_Jaxb2 - Fatal编程技术网

Java 关于JAXB2.x SchemaGen的问题

Java 关于JAXB2.x SchemaGen的问题,java,xsd,jaxb2,Java,Xsd,Jaxb2,我正在尝试使用jaxb从我现有的POJO类生成模式,到目前为止工作正常。现在我需要声明一个属性类型是我的XSD,但属性值应该是预定义值之一。 下面是我班上的代码快照 private String destinationID; private String contactNo; private String type; @XmlAttribute private String name; 我的要求是,名称应该包含与此模式类似的任何预定义值 <xsd:attribute name="type

我正在尝试使用jaxb从我现有的POJO类生成模式,到目前为止工作正常。现在我需要声明一个属性类型是我的XSD,但属性值应该是预定义值之一。 下面是我班上的代码快照

private String destinationID;
private String contactNo;
private String type;
@XmlAttribute
private String name;
我的要求是,名称应该包含与此模式类似的任何预定义值

<xsd:attribute name="type"
        type="simpleType.Generic.ProductReferenceType" use="required" />
<xsd:simpleType name="simpleType.Generic.ProductReferenceType">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="OFFER" />
        <xsd:enumeration value="SELLER" />
        <xsd:enumeration value="DEFINITION" />
    </xsd:restriction>
</xsd:simpleType>

我无法找出我需要在课堂上做些什么才能达到这个目的


提前感谢

您可以这样定义枚举:

@XmlType(name="simpleType.Generic.ProductReferenceType")
public enum ProductReferenceType { 
    OFFER,
    SELLER,
    DEFINITION
}
然后在课堂上简单地使用它:

@XmlAttribute
public ProductReferenceType type;
这将生成XSD,如下所示:

  <xs:simpleType name="simpleType.Generic.ProductReferenceType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="OFFER"/>
      <xs:enumeration value="SELLER"/>
      <xs:enumeration value="DEFINITION"/>
    </xs:restriction>
  </xs:simpleType>



祝你的项目好运

谢谢!!!!,我已经实现了一些类似的东西,让你的答案被接受,这样其他寻找这种东西的人可以得到好处
    <xs:attribute name="type" type="simpleType.Generic.ProductReferenceType"/>