SpringBoot 基础 常用注解
1、@SpringBootApplication = @SpringBootConfiguration + @EnableAutoConfiguration + @ComponentScan
@RestController = @[email protected]
打开源码可以看见:
2、@RequestMapping(path = "/{id}", method = RequestMethod.GET)
可以在参数中使用(@PathVariable String id )代替
3、@GetMapping = @RequestMapping(method = RequestMethod.GET)
@PostMapping = @RequestMapping(method = RequestMethod.POST)
@PutMapping = @RequestMapping(method = RequestMethod.PUT)
@DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)
4、@RequestParam(value = "name", required = true)
可以设置默认值,比如分页
5、@RequestBody 请求体映射实体类
需要指定http头为 content-type为application/json charset=utf-8
6、@RequestHeader 请求头,比如鉴权
@RequestHeader("access_token") String accessToken