Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java soap对象应该使用构造函数还是setter进行创建?_Java_Web Services_Soap_Jaxb - Fatal编程技术网

Java soap对象应该使用构造函数还是setter进行创建?

Java soap对象应该使用构造函数还是setter进行创建?,java,web-services,soap,jaxb,Java,Web Services,Soap,Jaxb,当创建JAXBjava对象以便与SOAPwebservices/jaxws一起使用时,从设计的角度来看,是通过构造函数还是通过它们的设置器填充这些对象更好 例如: @XmlRootElement Customer { int id; String name; int age; String birthdate; String notes; Address address; } 使用以下任一选项: customer.setId(..); custo

当创建
JAXB
java对象以便与
SOAP
webservices/jaxws一起使用时,从设计的角度来看,是通过构造函数还是通过它们的设置器填充这些对象更好

例如:

@XmlRootElement
Customer {
    int id;
    String name;
    int age;
    String birthdate;
    String notes;
    Address address;
}
使用以下任一选项:

customer.setId(..);
customer.setName();
customer.setAge();
customer.setBirthdate();
customer.setNotes();
customer.setAddress();
或:


JAXB要求您有一个零参数构造函数(尽管它可以是私有的)。除此之外,如何填充对象并不重要。

我知道如何填充字段对jaxb来说并不重要,但可能从设计的角度来看。。
new Customer(12, "testname", 19, 2014-03-03, "test", new Address("streetname", 12345, "town"));