Java Spring Restcontroller帖子 [英] Java Spring Restcontroller Post

查看:95
本文介绍了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"

请帮助!

推荐答案

您可以进行以下检查.

  1. 通过一些在线工具验证您要发送的请求正文 JSonLint .
  2. 检查是否已注册MappingJackson2HttpMessageConverter.默认情况下,如果您在类路径中有jar,Spring将注册此转换器.
  3. 如果使用的是@RestController,则无需使用@ResponseBody.因此,将其删除.
  1. Validate the request body you are sending through some online tool like JSonLint.
  2. Check whether MappingJackson2HttpMessageConverter is registered or not. By default, Spring registers this converter if you have the jar in the classpath.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆