在Spring Boot中,@RequestParam注解用于将HTTP请求中的参数绑定到方法的参数上。具体使用方式如下:
@GetMapping("/example")
public String exampleMethod(@RequestParam("paramName") String paramValue) {
// 方法体
}
在HTTP请求中,通过查询字符串的方式传递参数。例如,通过URL的形式传递参数:http://localhost:8080/example?paramName=value
。
可以使用@RequestParam注解的属性来控制参数的行为:
@GetMapping("/example")
public String exampleMethod(@RequestParam(value = "paramName", required = false, defaultValue = "default") String paramValue) {
// 方法体
}
注意事项:
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>