使用Spring,我如何正确地接收下面的POST请求,以便返回结果?
public ResponseEnvelope sendHalfMap(GameID gameID, PlayerID playerID) throws Exception
{
java.util.List<HalfMapNode> mapNodes = MapGenerator.generator();
HalfMap halfMapMessageBody = new HalfMap(playerID.getID(), mapNodes);
URL halfMapUrl = new URL(baseUrl, "game/" + gameID.getID() + "/halfmap");
RestTemplate restTemplate = getRestTemplate();
ResponseEnvelope requestResult = (ResponseEnvelope)restTemplate.postForObject(halfMapUrl.toURI(), halfMapMessageBody, ResponseEnvelope.class);
return requestResult;
}发布于 2019-01-05 01:59:39
在异常消息中可以看到该问题:
Main.NewMapNode does not have a no-arg default constructor.如果NewMapNode类没有默认的、无参数的构造函数,Spring MVC框架将无法为NewMapNode创建JAXB上下文,因此会失败。如果无法为该类创建默认的无参数构造函数,请参阅this SO answer了解如何创建客户XmlAdapter。
https://stackoverflow.com/questions/54043592
复制相似问题