为grails中的hasMany字段设置XmlAttribute

Setting XmlAttribute for hasMany field in grails

我正在实施一项服务,我使用 XJC 从 XSD 文件创建域 类。生成的 Java 我已移植到 grails,但我无法在这些字段上设置 XMLAttributes 注释,至少我不知道如何设置。你是怎么做到的?

这里是我要给出的想法:


import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlAttribute
import javax.xml.bind.annotation.XmlType

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AuditSourceIdentificationType", propOrder = [
        "auditSourceTypeCode"
])
class AuditSourceIdentificationType {

    static hasMany = [
            auditSourceTypeCodes: CodedValue //@XmlElement(name = "AuditSourceTypeCode")?
    ]

    @XmlAttribute(name = "AuditEnterpriseSiteID")
    String auditEnterpriseSiteID

    @XmlAttribute(name = "AuditSourceID", required = true)
    String auditSourceID
}

如有任何帮助,我们将不胜感激。

好的,我把它搁置了几天,这正是我所需要的。事实证明,我并没有真正考虑域 类 的真正设置方式,出于某种原因,除了将它们放在 hasMany 声明中之外,我没有将它们声明为 List。这就是为 hasMany 字段设置注释的方式。

自从我建立一个 grails 项目以来已经有一段时间了,它确实有助于跟上你的实践。更正以下代码:

import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlElement
import javax.xml.bind.annotation.XmlRootElement
import javax.xml.bind.annotation.XmlType

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = [
        "eventIdentification",
        "activeParticipant",
        "auditSourceIdentification",
        "participantObjectIdentification"
])
@XmlRootElement(name = "AuditMessage")
class AuditMessage {

    static hasMany = [
            activeParticipants: ActiveParticipant,
            auditSourceIdentifications: AuditSourceIdentificationType,
            participantObjectIdentifications: ParticipantObjectIdentificationType
    ]

    @XmlElement(name = "ActiveParticipant", required = true)
    List activeParticipants

    @XmlElement(name = "AuditSourceIdentification", required = true)
    List auditSourceIdentifications

    @XmlElement(name = "ParticipantObjectIdentification")
    List participantObjectIdentifications

    String auditMessageText

    @XmlElement(name = "EventIdentification", required = true)
    EventIdentificationType eventIdentification
}'''