简体   繁体   English

我的课程在哪里放置@XmlElement注释?

[英]Where in my Class do I put the @XmlElement Annotation?

In my JAXB classes, do I put the @XmlElement annotation above the private variable declaration? 在我的JAXB类中,我是否将@XmlElement注释放在私有变量声明之上?

@XmlElement(name = "report_name")
private String name;

Above the setter? 在二传手的上方?

@XmlElement(name = "report_name")
public void setName(String name) {
    this.name = name;
}

Or above the getter? 或者在吸气剂上方?

@XmlElement(name = "report_name")
public String getName() {
    return name;
}

I've read through several JAXB tutorials and have yet to find a consistent pattern. 我已经阅读了几篇JAXB教程,但还没有找到一致的模式。

By default JAXB impls treat public fields and properties as mapped. 默认情况下,JAXB impls将公共字段和属性视为映射。 You can put the annotation on the get or set method and it will be treated the same. 您可以将注释放在get或set方法上,它将被视为相同。 If you want to annotate the field you should specify @XmlAccessorType(XAccessType.FIELD) on the class. 如果要注释该字段,则应在类上指定@XmlAccessorType(XAccessType.FIELD)

For More Information 欲获得更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM