大致說了一些基礎功能。這篇來看看它全部的功能
1.全自動
如果注入沒有歧義,沒有特別的需求,只是要完成注入,則只要extends autowire,或者對類定義處進行@wire註解標明,即可完成注入
不過對於@wire註解標註的類,直接使用new來例項化是不能自動注入的,但是繼承autowire的類可以隨意例項化,若在例項化過程中「遇到」@wire註解的類,就會對@wire標註的類進行自動注入。
如果有歧義或者額外的需求(比如不希望某個setter被執行,或者強制讓值為某個bean),比如setter是以介面方式定義的,就需要註解的幫忙了。
2.註解:
在框架使用中,通過註解進行配置是非常方便的,可以減少很多的xml語句。
所以,為了盡可能簡單,必須指定配置的地方都使用註解完成。
預設提供這些註解:
@target(elementtype.type)
public @inte***ce bean
@target()
public @inte***ce default
@target()
public @inte***ce force
@target( )
public @inte***ce ignore
@target(elementtype.type)
public @inte***ce issingleton
@target( )
public @inte***ce use
@target(elementtype.type)
public @inte***ce wire
從上述**,以及注釋中可以了解每個annotation的功能以及用在何處(@target註解標明了位置)。
所以用法也顯而易見了~~稍稍舉一反三一下就好。
3.自定註解 / 註解解釋
乙個沒有擴充套件性的程式不是好程式
——wkgcass
開個玩笑= =
擴充套件性對程式是極其重要的。這裡最大的可擴充套件點就是註解。所以註解必須可擴充套件
那麼如何擴充套件呢?看如下4個介面:
public inte***ce constructorfilter
public inte***ce paramannotationhandler
public inte***ce setterannotationhandler
public inte***ce typeannotationhandler
從上到下依次為:
constructor過濾器,用於選取特定的構造器,返回選取後的過濾器,選取失敗返回null
引數註解處理,返回生成/取出的引數,失敗則丟擲異常
setter註解處理,用於執行(invoke)指定的setter,執行成功返回true,失敗返回false
型別註解處理,用於對型別進行操作,比如@default註解,就需要這類介面實現乙個handler去選取指定的類。
大家還能發現,每個介面的handle方法都有乙個chain引數,它是這兒程式設計思想的主體之一
其中priority作用是區分先後。數值越低,則在chain中排得越早。注意:如果priority相同,那麼相同數值的所有同型別handler只有乙個會執行。
乙個例子**:
/**
* priority 0.0
* * default implementation of paramannotationhandler
* simply return the corresponding value of given parameter type.
* @author wkgcass
* */
public class defaultparamhandler extends ioccontroller implements
paramannotationhandler
@override
public object handle(member caller, class<?> cls, annotation tohandle,
paramhandlerchain chain) throws annotationhandlingexception
trycatch(annotationhandlingexception e){}
if(autowire.debug_mode)
} @override
public double priority()
}
並且在ioccontroller中註冊(呼叫static的register方法)即可
以類似的方式,可以完成更多自定義註解操作!
struts分頁的一種實現! 二
查詢action的 片斷 3 翻頁action的 片斷 file 讀 取翻頁引數 turnpageform turnpageform turnpageform form file 從 pagecontroller中取出查詢資訊,並使用bean提供的呼叫介面處理結果 file 根 據引數將資料寫入 r...
一種定位記憶體洩露的簡易方法
在這篇文章中,將介紹一種定位記憶體洩露的方法。主要原理是通過記憶體洩露時分配的序號以及大小,配合dbgheap.c檔案來定位。在vs開發過程中,開啟crt內部的記憶體洩露檢測函式,當程式退出時,在除錯視窗會輸出未釋放的記憶體資訊,例如下圖所示 從上面截圖可以得知,該次記憶體分配序號為1789698,...
一種分頁的實現
以下 是一種分頁的實現。分別是檔案page.php和page.css。分頁的糾結點在於分頁條中省略號的顯示。實現的基本邏輯是 1,接收瀏覽器端傳過來的想要顯示的頁碼數 page。page get p 2,根據頁碼數 page 以及固定的每頁顯示數 pagesize 從資料庫中取資料。sql sele...