@RequestMapping(value = "/NewCustomer", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
private void vNewCustomer(@RequestBody Customer xCustomer)
{
System.out.println("Post Request");
if(xCustomer != null
&& xCustomer.getCustomerName() != null
&& xCustomer.getCustomerMail() != null)
{
TableCustomerController.vGetInstance().vInsertCustomer(xCustomer);
}
}
它回来了 已解决 [org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型“text/plain;charset=UTF-8”]
我该如何解决 谢谢你的帮助..
在您的方法中,您专门配置了
consumes = MediaType.APPLICATION_JSON_VALUE
。因此,您限制了您的方法并指定使用此类型,然后您抱怨它不采用不同的类型。因此,要么删除 consumes
属性,要么将其设置为 MediaType.TEXT_PLAIN
或仅设置为字符串 consumes = "text/plain;charset=UTF-8"
可以检查映射json请求时是否有异常。 我遇到了无法评估类型 [...] 的 Jackson 反序列化。属性 [...] 的 getter 定义冲突。修复它例外,问题将得到解决。