氣泡排序演算法
阿新 • • 發佈:2020-09-01
在Spring4之後,要使用註解開發,必須保證aop的包被匯入了,匯入context的約束,增加註解的支援
1.bean
@Component
2.屬性如何注入
@value
package com.yl.pojo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
//等價於<bean id = "user" class = "com.yl.pojo.User">
3.衍生註解
@Component有幾個衍生註解,我們在web開發中,會按照mvc三層架構分層。
-
dao:@Repository
-
service:@Service
-
controller:@Controller
這四個註解功能都是一樣的,都是代表將某個類註冊到Spring中,裝配Bean
4.作用域
@Scope:@Scope("singleton")
xml與註解:
-
xml更加萬能,適用於任何場合,維護簡單方便
-
註解:不是自己類使用不了,維護相對複雜
-