我对 Jaxb 和这个 maven-jaxb2 插件非常陌生
这是我的 .xsd 文件:
<xs:element name="user" type="user" />
<xs:element name="userList" type="userList" />
<xs:complexType name="user">
<xs:all>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="name" type="xs:string" />
<xs:element name="registrationDate" type="xs:dateTime" />
</xs:all>
</xs:complexType>
<xs:complexType name="userList">
<xs:sequence>
<xs:element name="user" type="user" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
这是我的 .xjb 文件:
<!-- Annotate @XmlRootElement Annotation for all the classes, that matches
in the .xsd with complexType -->
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType['1'='1']" multiple="true"
required="false">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
name="user" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
当它生成它时,它给了java类有点像:
XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "user", propOrder = {
})
@Entity
@XmlRootElement(name = "${@name}")
@Table(schema = "schemaName", uniqueConstraints = {
}, name = "user_")
public class User
implements Serializable, ToString
{
private final static long serialVersionUID = 1L;
protected Long id;
它应该在哪里给出名称=对象名称,例如这里的“用户”我知道如果我写这样的绑定它会生成
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='user']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" />
</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='userList']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="userList" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
但我不想为用户和用户列表重复相同的代码,有什么方法可以通过注释或定义正则表达式来完成。请提出一些方法。
我只是想知道在这段代码中写什么
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
name="user" />
</annox:annotate>
因此,当它创建用户类时,它会显示 @xmlRootElement(name='user') 并且对于其他类 @xmlRootElement(name='userList') 和其他类类似。