Java Spring Restcontroller帖子 [英] Java Spring Restcontroller Post
本文介绍了Java Spring Restcontroller帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助向Java Spring Restcontroller创建POST请求.
I need help creating a POST request to my Java Spring Restcontroller.
这是我的控制器-
@RestController
@RequestMapping("hedgesimulator/")
public class HedgeSimulatorController {
@RequestMapping(value = "hedgesim/", method = RequestMethod.POST)
@ResponseBody
public HedgeSimulatorLog putHedgeSimulation(
@RequestBody HedgeSimulatorLog hedgeSimulatorLog) {
System.out.println(hedgeSimulatorLog.toJsonString());
return hedgeSimulatorLog;
}
}
我正在使用Chrome的"Advanced Rest Client"插件将请求发布到我的URL(我确定本地主机运行正常,等等)
I am using Chrome's "Advanced Rest Client" Plugin to POST my request to my URL (I am sure my localhost is running properly, etc.)
我需要在标题中添加什么?
我收到"HTTP 400-状态报告:客户端发送的请求在语法上不正确"的错误
I receive an error for "HTTP 400 - Status report: The request sent by the client was syntactically incorrect"
请帮助!
推荐答案
您可以进行以下检查.
- 通过一些在线工具验证您要发送的请求正文 JSonLint .
- 检查是否已注册
MappingJackson2HttpMessageConverter
.默认情况下,如果您在类路径中有jar,Spring将注册此转换器. - 如果使用的是
@RestController
,则无需使用@ResponseBody
.因此,将其删除.
- Validate the request body you are sending through some online tool like JSonLint.
- Check whether
MappingJackson2HttpMessageConverter
is registered or not. By default, Spring registers this converter if you have the jar in the classpath. - No need to use
@ResponseBody
if you are using@RestController
. So remove it.
有关使用Spring 4.0
创建和使用REST服务的完整示例,您可以访问技术点.
For a complete example on creating and consuming REST Service using Spring 4.0
, you can visit Techno Spots.
这篇关于Java Spring Restcontroller帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文