gpt4 book ai didi

java - 使用 REST 访问 JPA 数据失败 找不到合适的 HttpMessageConverter

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:00:22 26 4
gpt4 key购买 nike

我已经为此苦苦挣扎了一段时间,但找不到解决方案。我正在运行 SpringBoot 指南,使用 REST 访问 JPA 数据 (http://spring.io/guides/gs/accessing-data-rest/) 不工作。

只要下载并运行它就可以正常运行,允许 GET 调用

http://localhost:8080/people 

使用 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!"
}

我通过 PUT 传递的 json 是

{
"firstName": "Dave",
"lastName": "Something"
}

这只是运行原始项目,没有任何更改。许多其他指南项目工作正常,所以我知道 MVN、Spring boot 等工作正常。

尝试了很多论坛,但没有任何建议有效。

如有任何帮助,我们将不胜感激。

谢谢戴夫

最佳答案

您的 POST 请求的内容类型为 text/plain,服务器不知道如何将纯文本转换为 hello.Person 实例。

您需要通过将请求的 Content-Type header 设置为 application/json 来告诉服务器您正在发送 JSON

关于java - 使用 REST 访问 JPA 数据失败 找不到合适的 HttpMessageConverter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27115334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com