專案中有些模組需要加入工作流審批流程,並且可以選擇是否開啟工作流。
於是根據需求就想到了用aop做乙個通用的模組開關檢驗。
如果模組沒有開啟工作流,就直接放行。如果開啟了工作流,就啟動該模組的工作流流程。
下面上**
@target(elementtype.method)
@retention(retentionpolicy.runtime)
public @inte***ce actannotation
@component
@aspect
public class actaop
/*** 對註解的解析 @around 通過環繞通知來控制業務邏輯
* proceedingjoinpoint pjoinpoint 目標方法
* actannotation actannotation 目標方法的註解物件
*/@around("pointcut() && @annotation(actannotation)")
public resultdto around(proceedingjoinpoint pjoinpoint, actannotation actannotation) throws throwable
//獲取該模組執行中的流程數量
if(actprocesscount < 1)
//開啟了模組開關 並且存在執行中的流程
object args = pjoinpoint.getargs();
switch (key)
return resultutil.error("沒有呼叫任何方法");
}//呼叫指定方法
private resultdto taskrelease(object args,actmoduleenum key)
}
@actannotation(key = actmoduleenum.task_release)
public resultdto realrelease(long id)
AOP 自定義註解
compile org.springframework.boot spring boot starter aop aspect component public class auditaspect before weblog public void debefore joinpoint joinpo...
通過 aop 寫 自定義註解
target elementtype.method retention retentionpolicy.runtime public inte ce iface1 target target說明了annotation所修飾的物件範圍 annotation可被用於 packages types 類 介...
自定義註解搭配AOP使用
首先敘述一下業務,在每個模組中達到某要求時都要給當前使用者新增積分,所以這裡用到了註解搭配aop。首先自定義乙個註解 author zhanggx date 2021 01 06 16 40 target retention retentionpolicy.runtime documented pu...