没有为类型列表的JAX B对象生成Setter方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了没有为类型列表的JAX B对象生成Setter方法相关的知识,希望对你有一定的参考价值。

对于maxOccurs = unbounded类型,当我从XSD创建JAX类时,不会生成Setter方法。我需要为DetailType手动添加setter方法。这是正确的方法,因为我需要在根元素内填充DetailType

@XmlRootElement(name = "WPExchangeRate")
public class WPExchangeRate {

    @XmlElement(name = "Header")
    protected HeaderType header;
    @XmlElement(name = "Detail", required = true)
    protected List<DetailType> detail;
    @XmlElement(name = "Trailer")
    protected TrailerType trailer;
答案

这是设计的。只是做getDetail().add(myDetail)

另一答案

如果您使用Maven: 在你的pom.xml中添加插件的<configuration>

<args>
    <arg>-Xsetters</arg>
</args>

如果要配置生成方法:-Xsetters-mode=accessor-Xsetters-mode=direct

如果从命令行生成: 将-Xsetters添加到命令中(对于-Xsetters-mode也是如此)。

以上是关于没有为类型列表的JAX B对象生成Setter方法的主要内容,如果未能解决你的问题,请参考以下文章