SpringBoot 基础 常用注解

1、@SpringBootApplication = @SpringBootConfiguration + @EnableAutoConfiguration + @ComponentScan

      @RestController = @[email protected]    

打开源码可以看见:

SpringBoot 基础 常用注解

 

 

2、@RequestMapping(path = "/{id}", method = RequestMethod.GET)

      可以在参数中使用(@PathVariable String id )代替
                

 


 3、@GetMapping = @RequestMapping(method = RequestMethod.GET)

SpringBoot 基础 常用注解
      @PostMapping = @RequestMapping(method = RequestMethod.POST)

SpringBoot 基础 常用注解
      @PutMapping = @RequestMapping(method = RequestMethod.PUT)

SpringBoot 基础 常用注解
      @DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)

SpringBoot 基础 常用注解

 

 

4、@RequestParam(value = "name", required = true)
                    可以设置默认值,比如分页 

 

 

5、@RequestBody 请求体映射实体类
                    需要指定http头为 content-type为application/json charset=utf-8

 

 

6、@RequestHeader 请求头,比如鉴权
                    @RequestHeader("access_token") String accessToken