Spring的@GetMapping,@PostMapping和@RestController注解

@GetMapping
用于将HTTP GET请求映射到特定处理程序方法的注释
是@RequsetMapping(method = RequestMethod.GET)的缩写,只接受get方式的请求

@PostMapping
用于将HTTPPOST请求映射到特定处理程序方法的注释
是@RequestMapping(method = RequestMethod.POST)的缩写,只接受post方式的请求

@RestController
相当于@ResponseBody与@Controller的结合
@RestController注解的方法无法返回jsp界面,只会返回return中的内容;返回json数据/xml/自定义media type

总结来说就是@PostMapping和@GetMapping都可以用@RequestMapping代替

猜你喜欢

转载自blog.csdn.net/weixin_43514899/article/details/108939581
今日推荐