String sourceAddress と int port の 2 つのフィールドを持つ非常に単純なクラスがあります。
jaxb のデフォルトの sourceAddress と sourcePort の代わりに、source/address ノードと source/port ノードにそれらをマッピングしたいと考えています。
だから私は MOXy @XmlPath アノテーションを使用します。
問題は、注釈が無視され、「jaxb default」xml ファイルを取得することです。
<szk>
<sourceAddress>test</sourceAddress>
<sourcePort>10000</sourcePort>
</sz>
助けてくれてありがとうアゴスティーノ
import javax.xml.bind.*; import javax.xml.bind.annotation.*; org.eclipse.persistence.jaxb.JAXBContext をインポートします。 org.eclipse.persistence.oxm.annotations.XmlPath をインポートします。 @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) 公開クラス SZK { @XmlPath("ソース/アドレス") プライベート文字列 sourceAddress; @XmlPath("ソース/ポート") プライベート int sourcePort; public static void main (String [] args) throws JAXBException{ SZK k = 新しい SZK(); k.sourceAddress = "テスト"; k.sourcePort = 10000; javax.xml.bind.JAXBContext jc = JAXBContext.newInstance(SZK.class); マーシャラー m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(k, System.out); } }