The @RequestParam annotation binds a query parameter, form field or multipart part of an HTTP request to a parameter of a Spring MVC controller method. Spring reads the value from the request, converts it to the declared Java type and passes it in, so you do not call request.getParameter() yourself. It also gives you required checks, default values and automatic 400 Bad Request responses when input is missing or malformed.
It works the same way in Spring MVC and in Spring Boot, because Boot uses Spring MVC underneath. Use it for simple, scalar inputs such as filters, paging and search terms. For path segments use @PathVariable, and for a JSON body use @RequestBody.
Spring treats "request parameters" as one concept: the query string (?page=2), URL-encoded form fields (application/x-www-form-urlencoded), and the parts of a multipart/form-data request. @RequestParam reads any of these by name.
A request to GET /greet?name=Asha returns Hello, Asha. Because the Java parameter is called name, Spring uses that as the request parameter name.
When you omit the name, Spring needs the real Java parameter name at runtime. That requires compiling with javac -parameters. Spring Boot's Maven and Gradle plugins and the Boot parent POM enable it for you. Since Spring Framework 6.1 there is no fallback to debug information, so a plain build without the flag fails with an error about a missing parameter name. To be explicit, or when the request name differs from the Java name, state it:
| Attribute | Purpose | Default |
|---|---|---|
value / name | Name of the request parameter | Java parameter name |
required | Whether the parameter must be present | true |
defaultValue | Fallback used when the parameter is missing or empty | none |
By default a missing parameter makes Spring throw MissingServletRequestParameterException, which is returned as 400 Bad Request. You can relax that in three equivalent ways.
defaultValue supplies a value and implicitly makes the parameter optional. It also applies when the parameter is present but empty.required = false passes null for a missing parameter, so it only works for reference types. A primitive such as int would fail with a conversion error.java.util.Optional<T> makes the parameter optional and avoids null checks.Request parameters are strings, and Spring converts them with its ConversionService. Common targets are numbers, booleans, enums, LocalDate (with @DateTimeFormat), and UUID.
GET /orders?from=2026-11-01&ids=1,2,3 and GET /orders?from=2026-11-01&ids=1&ids=2&ids=3 both bind ids to [1, 2, 3]. If a value cannot be converted, for example ids=abc, Spring throws MethodArgumentTypeMismatchException and responds with 400.
To accept arbitrary parameters, bind them to a map. MultiValueMap keeps repeated values.
For a classic HTML form submitted as application/x-www-form-urlencoded, @RequestParam reads the fields exactly as it reads a query string.
For file uploads, bind the file part to a MultipartFile:
If a part is a JSON document or you need to validate it as an object, use @RequestPart instead.
Spring's default handling maps binding failures to 400. To return a consistent error body, handle the exceptions centrally:
For range and format checks, add Bean Validation constraints. In Spring Framework 6.1 and later, method validation on controller parameters works when the constraint annotations are present, for example @RequestParam @Min(1) int page. Older versions needed @Validated on the controller class.
| Annotation | Reads from | Typical use |
|---|---|---|
@RequestParam | Query string, form fields, multipart parts | Filters, paging, simple form input |
@PathVariable | URI template segment, such as /users/{id} | Resource identifiers |
@RequestBody | Whole request body via a message converter | JSON or XML payloads |
@RequestPart | One part of a multipart request via a converter | File plus JSON metadata |
@RequestHeader | HTTP header | Tokens, content negotiation |
@ModelAttribute | Many parameters bound to an object | Form objects |
Yes. required is true, so a missing parameter results in 400 Bad Request. Set required = false, add a defaultValue, or use Optional to make it optional.
@RequestParam reads from the query string or form data (/users?id=5), while @PathVariable reads from the path (/users/5). Path variables identify a resource, and request parameters usually filter or modify it.
No. A JSON body is not a request parameter. Use @RequestBody with a class or record, and Jackson converts it for you.
The code was compiled without -parameters, so Spring cannot read the parameter name. Enable the flag or write the name in the annotation, for example @RequestParam("q").
Yes. It reads URL-encoded form fields and multipart parts from a POST body as well as the query string.
@RequestParam extracts simple values from the query string, form fields or multipart parts and converts them to the types your handler declares. Control its behaviour with name, required and defaultValue, or use Optional. Prefer @PathVariable for resource identifiers and @RequestBody for JSON, and handle MissingServletRequestParameterException centrally so clients get clear errors.