我正在實作一個服務,我使用 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
}
任何幫助將不勝感激。
uj5u.com熱心網友回復:
好的,我把它放下了幾天,這正是所需要的。事實證明,我并沒有真正考慮域類的真正設定方式,出于某種原因,除了將它們放在 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
}'''
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/351327.html
上一篇:無法使用嵌入式物件發布JSON-它讀取和存盤除物件串列(OneToMany)之外的所有內容-SpringBootAPI( 休眠)
