Dav*_*dea 8 java rest spring jpa spring-boot
我一直在和这个争斗一段时间,无法找到解决方案.我正在运行SpringBoot指南,并且使用REST 访问JPA数据(http://spring.io/guides/gs/accessing-data-rest/)不起作用.
只需下载并运行它就可以正常运行GET
http://localhost:8080/people
Run Code Online (Sandbox Code Playgroud)
使用POSTMAN.但是每当我尝试PUT或POST时,我都会收到以下错误
{
"cause": null,
"message": "No suitable HttpMessageConverter found to read request body into object of type class hello.Person from request with content type of text/plain;charset=UTF-8!"
}
Run Code Online (Sandbox Code Playgroud)
我和PUT一起经过的json是
{
"firstName": "Dave",
"lastName": "Something"
}
Run Code Online (Sandbox Code Playgroud)
这只是运行vanilla项目而没有任何变化.很多其他指南项目工作正常,所以我知道MVN,Spring启动等工作正常.
尝试了很多论坛,但没有任何建议的作品.
任何帮助将不胜感激.
谢谢戴夫
And*_*son 23
您的POST请求的内容类型为text/plain
,服务器不知道如何将纯文本转换为hello.Person
实例.
您需要通过将Content-Type
请求的标头设置为来告诉服务器您正在发送JSONapplication/json