下列Spring MVC注解中,可以映射多种HTTP请求类型的是( ) ?
参考答案:
在Spring MVC中,可以映射多种HTTP请求类型的注解是@RequestMapping。这个注解可以处理多种HTTP请求方法,如GET、POST、PUT、DELETE等。
例如:
@RequestMapping(value = "/example", method = {RequestMethod.GET, RequestMethod.POST})
public String handleRequest() {
// 处理请求
return "response";
}
在这个例子中,@RequestMapping注解映射了路径/example,并且可以接受GET和POST请求。当这个URL被GET或POST请求时,handleRequest方法会被调用。
需要注意的是,@GetMapping、@PostMapping、@PutMapping、@DeleteMapping等注解都是@RequestMapping的特例,它们分别只映射一种HTTP请求方法。例如,@GetMapping("/example")只会映射GET请求到/example路径。