postman的Params和Body的区别

postman有两个地方都可以输入参数变量和值,他们有什么区别呢?

1.Params处设置的变量请求时会变成http://********?*******问号后面的参数带到请求的接口链接里。

//这种是通过params传递(RequestParam)

@PostMapping("/detail")
public Result detail(@RequestParam Integer id) {
    EdgeNode edgeNode = edgeNodeService.findById(id);
    return ResultGenerator.genSuccessResult(edgeNode);
}

curl --location --request POST ‘localhost:8080//edge/node/detail?id=1’

  1. 而Body里设置的参数则是接口真正请求时发的参数

//这种是通过body(RequestBody)

@RequestMapping(value = "/detail", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public Result detail(@RequestBody JSONObject json) {
    Integer id = Integer.valueOf(json.getString("id"));
    EdgeNode edgeNode = edgeNodeService.findById(id);
    return ResultGenerator.genSuccessResult(edgeNode);
}

//(另外,这里注意header:Content-Type=application/json)

curl --location --request POST ‘localhost:8080//edge/node/detail?id=1’
–header ‘Content-Type: application/json’
–data-raw ‘{
“id”:“1”
}’

你可能感兴趣的:(postman的Params和Body的区别)