您如何自定义JAXB如何生成复数方法名称?

您如何自定义JAXB如何生成复数方法名称?,第1张

您如何自定义JAXB如何生成复数方法名称?

默认情况下,为您的架构片段生成以下内容

    import java.util.ArrayList;    import java.util.List;    import javax.xml.bind.annotation.XmlAccessType;    import javax.xml.bind.annotation.XmlAccessorType;    import javax.xml.bind.annotation.XmlElement;    import javax.xml.bind.annotation.XmlType;    @XmlAccessorType(XmlAccessType.FIELD)    @XmlType(name = "physicianList", propOrder = {        "physician"    })    public class PhysicianList {        @XmlElement(name = "Physician")        protected List<Physician> physician;        public List<Physician> getPhysician() { if (physician == null) {     physician = new ArrayList<Physician>(); } return this.physician;        }    }

如果您注释XML模式:

    <xs:schema        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"        xmlns:xs="http://www.w3.org/2001/XMLSchema"        jaxb:version="2.1">        <xs:complexType name="physician"> <xs:sequence> </xs:sequence>        </xs:complexType>        <xs:complexType name="physicianList"> <xs:sequence>     <xs:element name="Physician"      type="physician"      minOccurs="0"      maxOccurs="unbounded"><xs:annotation>    <xs:appinfo>        <jaxb:property name="physicians"/>    </xs:appinfo></xs:annotation>      </xs:element> </xs:sequence>        </xs:complexType>    </xs:schema>

然后,您可以生成所需的类:

import java.util.ArrayList;import java.util.List;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name = "physicianList", propOrder = {    "physicians"})public class PhysicianList {    @XmlElement(name = "Physician")    protected List<Physician> physicians;    public List<Physician> getPhysicians() {        if (physicians == null) { physicians = new ArrayList<Physician>();        }        return this.physicians;    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5499576.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存