为grails中的hasMany字段设置XmlAttribute



我正在实现一个服务,我使用XJC从XSD文件为该服务创建域类。我已经将生成的Java移植到grails中,但是我不能在这些字段上设置xmlatattributes注释,至少我不知道如何设置。你是怎么做到的?

我在这里给出一个想法:


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
}'''

相关内容

  • 没有找到相关文章

最新更新