註解的學習

2021-10-02 23:16:37 字數 773 閱讀 8273

 註解它不是注釋,注釋是程式設計師寫的,給程式設計師看的。

 註解給程式看,用於描述程式如何執行及在什麼階段來執行。

 註解在實際開發中,最大的功能是用於替換配置檔案。

 註解是jdk1.5的新特性

 可以通過反射來讓註解具有功能。

 註解的格式: @***x

 註解它的本質就是乙個介面,這個介面需要繼承 annotation介面

@override:檢查子類確實是覆蓋/重寫了父類的方法。

@deprecated:說明已經過時了。

@suppresswarnings():抑制程式中的警告。unused警告的型別。{}陣列。all抑制所有警告

只能用在註解上的註解叫做元註解。(即:用於修飾註解的註解)

a、自定義的註解的存活範圍(生命週期):預設是class。

b.@retention:作用。改變自定義的註解的存活範圍。

屬性retentionpolicy:

屬性值source、class、runtime

c.@target:作用,指定該註解能用在什麼地方。

屬性elementtype:

屬性值type:、method:、field:、annotation_type

1.webfilter("/*")

2.webservlet("/loginservlet")

省去了.xml的配置

spring註解學習

宣告bean的註解 注入bean的註解 配置檔案的註解 aop切面程式設計註解 spring 常用配置 postconstruct 在建構函式執行完之後執行 predestroy 在 bean 銷毀之前執行 activeprofiles 用來宣告活動的 profile profile 為不同環境下使...

Java註解學習

inte cepublic inte ce testannotation testannotation public class test retention retentionpolicy.runtime public inte ce testannotation elementtype.cons...

spring註解學習

如果使用以下註解,請在spring配置bean檔案中加上 讓它知道它去 掃瞄你的註解 component 形式 component value component 作用 用於把當前類物件存入 spring 容器中 屬性 value 用於指定 bean 的 id,預設是當前類名,且首字母改小寫 當值只...