自定義註解和反射例項

2021-07-02 13:31:09 字數 385 閱讀 4643

自定義註解和反射例項

/**

* @author 這個例子是說實體和資料庫對應表的對映,可以在實體上面使用註解。

* */

public class tannotationclass

}// => 下面是備註接的類

class person

// => 下面是自定義註解

@target(elementtype.field)

// 註解是給屬性使用的

@retention(retentionpolicy.runtime)

// 執行時不消除註解

@inherited

@inte***ce tablefieldname

自定義註解 反射

需求 在做許可權平台的時候,需要寫乙個查詢審計記錄列表的介面。這個需求看起來非常簡單,就是從資料庫單錶裡面查出資料,返回json格式。然而,資料庫裡有兩列,修改前和修改後的json。需要翻譯成字串整個返回。資料庫的source欄位的json長這樣 status used end date is de...

自定義註解例項

1.定義乙個全域性註解 要求登入 要求登入註解 target retention retentionpolicy.runtime documented public inte ce needlogin target 表示的是註解可以使用的範圍,這裡用於描述方法和 描述類 介面 包括註解型別 或enu...

基於自定義註解annotation 例項

1,自定義註解格式 target elementtype.method retention retentionpolicy.runtime public inte ce needjsonnullreplace2,註解實現類 public class jsonnullreplaceadvice els...