【问题标题】:Invoking service with @RequestParam and @RequestBody using postman client使用邮递员客户端使用@RequestParam 和@RequestBody 调用服务
【发布时间】:2015-06-22 11:55:56
【问题描述】:

正在尝试调用服务 http://IP:8080/PQRS/LMN/XYZ/runTest/scheduledautomation/1/XYZ

使用下面的 JSON 字符串

[ {"paramName":"TEST_TARGET_IDENTIFIER","paramValue":"ETest"},{"paramName":"TEST_SOURCE_ENTRY_IDENTIFIER","paramValue":"com.pack.etest"}]
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@RequestMapping(value = "/runTest/scheduledautomation/{runId}/{testEngine}", method = RequestMethod.POST)
public void runScheduledAutomatedTest(@RequestParam String cronExpresssion,
        @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime endTime,
        @PathVariable Integer runId,
        @PathVariable TestEngine testEngine,
        @RequestBody List<TestEngineParam> testEngineParams) throws Exception { //Some Code }

回应:

必需的字符串参数“cronExpresssion”不存在

如何在邮递员客户端调用@RequestParam@RequestBody混合服务?

【问题讨论】:

  • 通过传递参数...您目前没有传递参数,只有 JSON。
  • 即您在 URL 的末尾缺少 ?cronExpresssion=blabla。注意这个参数名中有3个s。在 POST 中使用请求参数是很奇怪的。为什么不将此信息作为 JSON 正文的一部分传递?

标签: spring postman


【解决方案1】:

我担心你想要的太多了:RequestParam、RequestBody 和整个事情作为一个 REST 查询。这三件事中至少有两件事是互斥的。

我认为您甚至可以通过将调用的 URL 修改为:

http://IP:8080/PQRS/LMN/XYZ/runTest/scheduledautomation/1/XYZ?cronExpression=your-expression

当然这会破坏你的 REST 接口,但正如我所说:你的处理程序方法有点“野心太大”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-02
    • 2017-09-06
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多