登陸的自定義註解 登入and日誌

2021-09-28 14:47:55 字數 2360 閱讀 2225

將登陸的自定義註解@loginrquire標註在方法上,表示該方法需要登陸才能夠呼叫。

/**

* @description: 自定義註解-登入

* @author: yufengpeng

* @createdate: 2019/9/16 20:03

* * @target : 用於描述註解的使用範圍

* * 也就是說使用了@target定義乙個註解,那麼可以決定定義好的註解可以使用在什麼地方

* * @retention : 用於描述註解的生命週期

* * 也就是說這個註解在什麼範圍內有效,註解的生命週期和三個階段有關:原始碼階段,class檔案有效,執行時有效

* * @documented : 表示該註解是否可以使用到api文件中

* * @inherited : 表示具備繼承性

* * 假設乙個註解在定義時,使用了@inherited,然後該註解在乙個類上使用,如果這個類有子類,那麼我們可以通過反射從類的子類上獲取到同樣的註解

*/@target(elementtype.method, elementtype.type)

@retention(retentionpolicy.runtime)

@documented

@inherited

public @inte***ce loginrequired ++

/**

* ***

*/@component

public class authwebshopinterceptor extends handlerinterceptoradapter

handlermethod myhandlermethod = (handlermethod) handler;

object bean = myhandlermethod.getbean();

method method= myhandlermethod.getmethod();

// 判斷介面是否需要登入

//類上有該標記

annotation classannotation = bean.getclass().getannotation(loginrequired.class);

//方法上有該標記

annotation methodannotation = method.getannotation(loginrequired.class);

// 有 @loginrequired 註解,需要認證

if (methodannotation != null || classannotation != null) else

}//已經在登入狀態

return true;

}//不需要登入驗證

return true;

}/**

* 在整個請求結束之後被呼叫,也就是在dispatcherservlet 渲染了對應的檢視之後執行(主要是用於進行資源清理工作)

* 後台日誌管理aop切面類

* * @author yufengpeng

*/@aspect

@component

public class managementlogaspect

/*** 方法成功執行後新增日誌

** @param joinpoint

*/@afterreturning(pointcut = "pointcut()")

public void afterreturning(joinpoint joinpoint)

settinglogdao.insert(log);

}}

自定義註解進行登入校驗

想起前段時間寫的寫的 自定義註解進行登入驗證 攔截請求,校驗有誤自定義的註解,有註解就需要校驗token,無註解即放行 這樣的好處就是在comment中寫乙個,整個專案都可以用,需要檢驗就加在那個方法上,很是靈活方便 廢話不少,上 自定義的註解類 在需要登入驗證的controller的方法上使用此註...

自定義註解

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

自定義註解

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