- @SpringBootApplication包含了@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan,一个注解相当于三个注解
- @RestController 相当于 @Controller+@ResponseBody
- GET,POST,PUT等请求相关
1)单一参数
@RequestMapping(path = "/{id}",method = RequestMethod.GET)
public String getUser(@PathVariable String id){
}
@GetMapping("/api/get")
public String getUser(String id){
}
2)多个参数
@RequestMapping(path = "/{depid}/{userid}",method=RequestMethod.GET)
public String getUser(@PathVariable("depid") String departmentID,@PathVariable("userid") String userid){
}
3)一个顶两个
@GetMapping = @RequestMapping(method = RequestMethod.GET)
@PostMapping = @RequestMapping(method = RequestMethod.POST)
@PutMapping = @RequestMapping(method = RequestMethod.PUT)
...
4)@RequestParam(value = "name",required = true),可以设置默认值
5)@RequestMapping + @RequestBody请求体映射实体类
注意:需要指定http头:content-type为application/json
6)@RequestHeader 请求头,比如鉴权
@RequestHeader("access_token") String accessToken
7)HttpServletRequest request自动注入获取参数