【问题标题】:How to send JSON from postman for a custom VO如何从邮递员发送 JSON 用于自定义 VO
【发布时间】:2019-11-28 02:18:29
【问题描述】:

我应该从 Postman 发送什么格式的 JSON 以将其正确映射到我的休息控制器。

TfundsVO :
BigDecimal accountNum
String accountName
BigDecimal accountBal



@GetMapping("/")
public ResponseEntity<Object> getFunds(@RequestBody TfundsVO tfundsVO) {
    System.out.println(tfundsVO.getAccountNum());
}

使用的示例 JSON:

{
    "tfundsVO": [
     {
        "accountName": "Sam"
     } 
  ]
}

当我从 Postman 尝试上述 JSON 时,调用转到 getFunds 方法,但是 TfundsVO 中的所有值都是 NULL。

【问题讨论】:

    标签: json spring get postman spring-restcontroller


    【解决方案1】:

    只发送不带数组的有效负载

    { "account name": "test" }
    

    请添加 application/json 标头作为内容类型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-03
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 2020-04-07
      • 2017-11-14
      • 1970-01-01
      • 2020-10-12
      相关资源
      最近更新 更多