簡體   English   中英

如果我們有以下字段,我們如何獲得字段名稱。 @XmlElement(必填= true)

[英]How do we get field name if we have field as below. @XmlElement(required = true)

如果我們有以下字段,我們如何獲得字段名稱。

@XmlElement(required = true) 
protected String code;  

如果我嘗試獲得:

Field f = clazz.getDeclaredField(field); 
XmlElement xmlElement = f.getAnnotation(XmlElement.class);  
xmlElement.name() // returns as ##default instead of code.

default僅表示使用Java Bean中的屬性名稱:

http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlElement.html#name%28%29

這里還有其他文章處理相同的問題,但似乎都沒有真正解釋如何獲得價值。 這是一個: 使用JAXB從未編組的Java對象中獲取xml元素名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM