首页 > 解决方案 > 为什么请求正文总是空的?

问题描述

我正在尝试创建简单的 spring CRUD,但是创建的发布请求总是空的。如果我手动填充对象 - 一切正常:

 @ResponseBody
 public Comment createOrUpdateComment(@RequestBody Comment comment) {

 comment.setIssueId(new Long(483162));
 comment.setUserId(new Long(2));
 comment.setComment("Comment");

 Comment updated = service.createOrUpdateComment(comment);
      return updated;
 }

没有手动设置 - 对象总是空的,并且无法像Column 'issue_id' cannot be null 我这样发送请求一样异常Postman

请求示例

感谢任何帮助!

标签: javaspringpost

解决方案


默认property-naming-strategy值为LOWER_CAMEL_CASE.

在 lowerCamelCase 中命名您的 JSON 属性,如下所示:

{
    "userId": 1,
    "issueId": 483162,
    "comment": "comment"
}

推荐阅读