I just want to know that how we can pass multiple variable or parameter in the message body by using the Spring boot.
Want to pass more than two variable in the postman as a parameter.
CodePudding user response:
Spring Boot not support multipe requestbody.
CodePudding user response:
Not sure I understand the question, but there are many ways to pass parameters to an API.
As a JSON object
If you just want to pass multiple parameters you'd just pass them in json format in the request body as a post or a put:
{
"firstName": "bob",
"lastName": "smith",
"middleName": "joe"
}
And your controller method would look something like
public Name createName(
@RequestBody Name name
) {}
As a JSON list
If you mean you have multiple values for the same parameter then you can pass them as a list.
[
{"firstName": "bob"},
{"firstName": "joe"},
{"firstName": "jerry"}
]
And your controller method would look something like
public List<Name> nameList createName(
@RequestBody List<Name> nameList
) {}
or
{
"firstNames": [
{"firstName": "bob"},
{"firstName": "joe"},
{"firstName": "jerry"}
]
}
And your controller method would look something like
public Names createName(
@RequestBody Names names
) {}
In this example Names would be an object that contains a variable
List<Name> nameList;
In the uri
Another option to pass values to the api is to include them a path parameters from postman your uri would look something like this:
using @RequestParam on the API
http://localhost:8080/apiPath?firstName=bob&lastName=smith&middleName=joe
or
using @PathVariable on the API
http://localhost:8080/apiPath/firstName/bob/lastName/smith/middleName/joe