我想在我的java類中註釋我的java方法爲@XmlTransient
,如下所示。在Jaxb 2.1中使用@XmlTransient註釋java方法時的問題2.1
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class MyClass {
@XmlTransient
public void addsomething{
// do something
}
}
當我嘗試通過其他類我的JAXBContext來使用這個類我得到以下異常
JAXB annotation is placed on a method that is not a JAXB property
this problem is related to the following location:
at @javax.xml.bind.annotation.XmlTransient()
,
但是,當我看到XmlTransient()
註釋定義(@Target(value={FIELD,METHOD,TYPE}))
這顯然說是使用方法。而在Javadoc(http://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlTransient.html)它說
The @XmlTransient annotation can be used with the following program elements:
a JavaBean property
field
class
我不能使用的方法@XmlTransient
?
沒有:),因爲Javadoc說你不能這麼做 – WeMakeSoftware
爲什麼你要將'XmlTransient'添加到'void'方法? –