springboot注解
1、@SpringBootApplication:结合@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan注解。
用途:用于spring boot入口类方法。
部分源码如下
@SpringBootConfiguration也是一个组合注解
2、@ComponentScan:让spring Boot扫描到Configuration类并把它加入到程序上下文。
3、@Configuration: 等同于spring的XML配置文件。
4、@EnableAutoConfiguration: 自动配置。
5、@ComponentScan :组件扫描。
6、@Component :定义Spring管理Bean。
7、@RestController:注解是@Controller和@ResponseBody的合集,映射HTTP请求,并且将函数的返回值直接填入HTTP响应体中。
8、@Autowired:按类型装配
9、@Resource: 按名称装配
10、@PathVariable: 接收url参数。
url="test/test?username=1&password=123";
@RequestMapping("/test")
public String test(@RequestParam Map<String, Object> paramMap ) {
return "";
}
11、@RequestParam:接收url参数。
@RequestMapping("/list/{id}")
public String list(@PathVariable("id") Integer id, HttpServletRequest request) {
request.setAttribute("cdId", id);
return "";
}
12、@GetMapping:是一个组合注解,是@RequestMapping(method =RequestMethod.GET)的缩写。
13、@PostMapping:是一个组合注解,是@RequestMapping(method =RequestMethod.POST)的缩写。
14、@Bean: 声明当前方法返回一个Bean。
15、@ExceptionHandler:遇到异常就执行这个方法。