@param @PathVariable
时间: 2023-10-12 16:11:08 浏览: 50
These are two annotations used in Spring MVC framework to handle HTTP requests.
- @param: This annotation is used to specify a method parameter and its description in the API documentation. It is used to document the input parameters of a method.
For example:
```java
@GetMapping("/users")
public List<User> getUsers(@RequestParam String name) {
// ...
}
```
In the above example, `@RequestParam` is used to specify the `name` parameter in the HTTP GET request.
- @PathVariable: This annotation is used to extract a variable from the URL path and bind it to a method parameter. It is used to handle dynamic URLs where the value of a parameter is not known in advance.
For example:
```java
@GetMapping("/users/{id}")
public User getUserById(@PathVariable Long id) {
// ...
}
```
In the above example, `@PathVariable` is used to extract the `id` variable from the URL path. The value of `id` will be bound to the `id` parameter of the method.