Web services 如何使用XML中的curl为SpringMVCWeb服务编写这篇文章

Web services 如何使用XML中的curl为SpringMVCWeb服务编写这篇文章,web-services,post,spring-mvc,curl,httpwebrequest,Web Services,Post,Spring Mvc,Curl,Httpwebrequest,这可能只是我的一个简单错误,但我无法使用XML中的curl来为我的web服务工作。web服务是使用SpringMVC创建的。我已经让它与PUT一起工作,并且我能够让它与POST和PUT-in-JSON一起工作。以下是控制器代码: // POST @RequestMapping(value = "/rest", method = RequestMethod.POST, headers = "Accept = application/xml") public void create(@Request

这可能只是我的一个简单错误,但我无法使用XML中的curl来为我的web服务工作。web服务是使用SpringMVC创建的。我已经让它与PUT一起工作,并且我能够让它与POST和PUT-in-JSON一起工作。以下是控制器代码:

// POST
@RequestMapping(value = "/rest", method = RequestMethod.POST, headers = "Accept = application/xml")
public void create(@RequestBody Item item) {
    itemServiceHibernate.addItem(item);
}

// PUT
@RequestMapping(value = "/rest", method = RequestMethod.PUT)
public void update(@RequestBody Item item) {
    itemServiceHibernate.updateItem(item);
}
工作PUT curl命令如下所示:

curl -X PUT -H 'Accept:application/xml' -H 'Content-Type: application/xml' http://localhost:8081/BarcodePayment/items/rest --data '<?xml version="1.0" encoding="UTF-8" standalone="no"?><item><id>4</id><description>firstItem</description><price>10.00</price><isVoid>false</isVoid><quantity>1</quantity><weight>4</weight><extendedPrice>10.00</extendedPrice></item>'

更多关于它如何“不工作”的信息会很有帮助,比如错误消息或其他什么。没有错误消息。POST创建了一个项,但所有项都为空。您是否有一个项的构造函数,该构造函数接受单个字符串并从中构建它?除非您告诉Spring,否则它将为您试图创建的对象寻找单个字符串构造函数。@Danalog。我已经编辑了这个问题,以包括我为Item类使用的构造函数方法。我从教程中了解了很多。谢谢
curl -X POST -H 'Accept:application/xml' -H 'Content-Type: application/xml' http://localhost:8081/BarcodePayment/items/rest --data '<?xml version="1.0" encoding="UTF-8" standalone="no"?><item><description>firstItem</description><price>10.00</price><isVoid>false</isVoid><quantity>1</quantity><weight>4</weight><extendedPrice>10.00</extendedPrice></item>'
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<item>
<description>firstItem</description>
<price>10.00</price>
<isVoid>false</isVoid>
<quantity>1</quantity>
<weight>4</weight>
<extendedPrice>10.00</extendedPrice>
</item>
// Initialization
public Item(){}
public Item(Long id, String description, double price, boolean isVoid, Long quantity, double weight, double extendedPrice) {
    this.id = id;
    this.description = description;
    this.price = price;
    this.isVoid = isVoid;
    this.quantity = quantity;
    this.weight = weight;
    this.extendedPrice = extendedPrice;
}