SpringBoot註解
一、聲明bean註解
1 | @Component | 通用註解 |
2 | @Controller | 表現層 |
3 | @Service | 業務邏輯層 |
4 | @Repository | 數據訪問層(dao層) |
5 | @RestController | 表現層,@Controller+@ResponseBody |
二、注入bean註解
1 | @Resource | |
2 | @Autowired | spring提供 |
3 | @Inject |
三、bean作用域、bean生命週期註解
1、bean的作用域
1 | @Scope |
1) singleton :單例,spring默認配置,一個spring容器中只有一個bean的實例,全容器共享一個實例。
2) Prototpe :多實例,每次調用創建一個bean實例
3) Request :
4) Session :
5) GlobalSession :
2、bean的生命週期
1 | ||
2 |
四、main方法入口註解
1 | @SpringBootApplication |
1 | ||
2 | ||
3 |
五、aop註解
1 | ||
2 | ||
3 | ||
4 |
一、Controller層
1 | @SpringBoorApplication | springboot啓動註解 |
2 | @configuration | springboot |
3 | @EnableAutoConfiguration | |
4 | @RestController | controller層註解,相當於@ResponseBody和@Controller的組合註解 |
5 | @Controller | controller層註解 |
6 | @ResponseBody | 返回json格式,與@Controller搭配使用 |
7 | @RequestMapping | 請求路徑限制 |
8 | @RequestParam | 讀取請求參數 |
9 |
二、Service層
1 | @Service | service層註解 |
2 | @Autowired | 自動裝配 |
3 | @Resource | 注入對象之間的關係 |
4 | @Value |
三、持久層
@Mapper
@Repository
1 | @Mapper | Dao層註解 |
2 | @Query | |
3 | @Param | |
4 |
四、表的映射
1 | @Entity | 實體類註解 |
2 | @Table | 表名 |
3 | @Id | 表中的id |
4 | @Transient |