Spring 常見注解
注解 |
說明 |
@Component、@Controller、@Service、@Repository |
使用在類上用于實例化Bean |
@Autowired |
使用在字段上用于根據(jù)類型依賴注入 |
@Qualifier |
結(jié)合@Autowired一起使用用于根據(jù)名稱進行依賴注入 |
@Scope |
標(biāo)注Bean的作用范圍 |
@Configuration |
指定當(dāng)前類是一個?Spring?配置類,當(dāng)創(chuàng)建容器時會從該類上加載注解 |
@ComponentScan文章來源:http://www.zghlxwxcb.cn/news/detail-558782.html |
用于指定?Spring???在初始化容器時要掃描的包 |
@Bean |
使用在方法上,標(biāo)注將該方法的返回值存儲到Spring容器中 |
@Import |
使用@Import導(dǎo)入的類會被Spring加載到IOC容器中 |
@Aspect、@Before、@After、@Around、@Pointcut |
用于切面編程(AOP) |
第一行中的?@Controller、@Service、@Repository 都是由?@Component 衍生而來
第四行中?@Scope 用于設(shè)置 Bean 是單例還是多例的,默認(rèn)情況下是單例
最后一行中?@Aspect、@Before、@After、@Around、@Pointcut 分別是定義 切面類、前置通知、后置通知、環(huán)繞通知、切點表達式
SpringMVC常見的注解
注解 |
說明 |
@RequestMapping |
用于映射請求路徑,可以定義在類上和方法上。用于類上,則表示類中的所有的方法都是以該地址作為父路徑 |
@RequestBody |
注解實現(xiàn)接收http請求的json數(shù)據(jù),將json轉(zhuǎn)換為java對象 |
@RequestParam |
指定請求參數(shù)的名稱 |
@PathViriable |
從請求路徑下中獲取請求參數(shù)(/user/{id}),傳遞給方法的形式參數(shù) |
@ResponseBody |
注解實現(xiàn)將controller方法返回對象轉(zhuǎn)化為json對象響應(yīng)給客戶端 |
@RequestHeader |
獲取指定的請求頭數(shù)據(jù) |
@RestController |
@Controller?+?@ResponseBody |
Springboot常見注解
注解 |
說明 |
@SpringBootConfiguration |
組合了-?@Configuration注解,實現(xiàn)配置文件的功能 |
@EnableAutoConfiguration |
打開自動配置的功能,也可以關(guān)閉某個自動配置的選 |
@ComponentScan |
Spring組件掃描文章來源地址http://www.zghlxwxcb.cn/news/detail-558782.html |
到了這里,關(guān)于Spring框架常見注解(Spring、Springboot、Springmvc)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!