Springboot在Controller中常用注解

@RestController

  @RestController相当于@Controller+@ResponseBody注解

  如果使用@RestController注解,Controller中的方法将无法返回页面,相当于方法上自动加了@ResponseBody注解

  所以没法跳转并传输数据到另一个页面,所以InternalResourceViewResolver也不起作用,返回的就是Return里的内容

@GetMapping

  @GetMapping注解是@RequestMapping(method=RequestMethod.GET)的缩写

@PostMapping

  @PosttMapping注解是@RequestMapping(method=RequestMethod.POST)的缩写

@PutMapping

  @PutMapping注解是@RequestMapping(method=RequestMethod.PUT)的缩写

@DeleteMapping

扫描二维码关注公众号,回复: 10750495 查看本文章

  @DeleteMapping注解是@RequestMapping(method=RequestMethod.DELETE)的缩写

猜你喜欢

转载自www.cnblogs.com/yz-bky/p/12690471.html