RequestParam
时间: 2023-10-14 12:25:58 浏览: 76
Spring MVC RequestParam.docx
@RequestParam is an annotation used in Spring MVC to bind a request parameter to a method parameter in a controller method. It is used to extract a single parameter value from the request URL query string or form data.
For example, consider the following URL: "http://localhost:8080/myapp/student?id=123". To extract the value of "id" from the URL, we can use the @RequestParam annotation as follows:
```
@GetMapping("/student")
public String getStudent(@RequestParam("id") int id) {
// Method implementation
}
```
In this example, the @RequestParam annotation is used to extract the value of the "id" parameter from the URL and bind it to the "id" method parameter. The method can then use this value to perform some action, such as retrieving the corresponding student record from a database.
The @RequestParam annotation also supports optional parameters, default values, and data type conversion.
阅读全文