Is there a way that when you have a code:
@PostMapping("/test")
public boolean test(@RequestBody String data) {
//code and stuff
}
You could send information in the post request url? for example
localhost:8080/test?username=username
Yes, just use @RequestParam:
@PostMapping("/test")
public boolean test(@RequestParam String username, @RequestBody String data) {
//code and stuff
}
In the reference documentation we can read the following:
Supported for annotated handler methods in Spring MVC and Spring WebFlux as follows:
- In Spring MVC, "request parameters" map to query parameters, form data, and parts in multipart requests. This is because the Servlet API combines query parameters and form data into a single map called "parameters", and that includes automatic parsing of the request body.
- In Spring WebFlux, "request parameters" map to query parameters only. To work with all 3, query, form data, and multipart data, you can use data binding to a command object annotated with ModelAttribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With