Spring 自定義註解案例

2021-08-16 07:31:59 字數 896 閱讀 1103

1. 自定義時間格式註解

@target(elementtype.field)//作用於字段上

@retention(retentionpolicy.runtime)//保留到執行期

public @inte***ce

dateparse

2. 自定義資料字典註解
@target(elementtype.field)//作用於字段上

@retention(retentionpolicy.runtime)//保留到執行期

public @inte***ce

dictparse

3. 定義轉換方法
public static t po2vo(object fromobj,classtocla) throws illegalargumentexception, illegalacces***ception, introspectionexception, invocationtargetexception, instantiationexceptionelse

}else}}

}}

return (t) toobj;

}

4. 使用(在vo中定義)
@dateparse(format = "yyyy-mm-dd")

private string createtime;

...get ... set ...

@dictparse(dictkey = "member_level")

private string level;

...get ... set ...

private string levelname;

...get ... set ...

spring中使用自定義註解

使用spring時,aop可以大幅度減少我們的工作量,這裡主要介紹一些spring中aop如何切註解。自定義註解 target retention retentionpolicy.runtime public inte ce myannotation 編寫切面類,切點在自定義註解上,切面類新增到sp...

自定義註解

target elementtype.field retention retentionpolicy.runtime public inte ce setvalue以上就是乙個自定義的註解,下面來進行說明。target elementtype.field 表示支援該註解的程式元素,field就是屬性...

自定義註解

三個重要元註解 target 即註解的作用域,用於說明註解的使用範圍 即註解可以用在什麼地方,比如類的註解,方法註解,成員變數註解等等 elemenettype.constructor 構造器宣告 elemenettype.field 域宣告 包括 enum 例項 elemenettype.loca...