AOP獲取註解定義的參數信息(二)

在上一篇中介紹的是AOP的日誌攔截配置,繼續作的是如何正確配置攔截信息java

 

首先,定義一個註解信息以及須要的參數web

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface logAnnotation {
	/**
	 * @param 模塊名字
	 */
	String modelName();

	/**
	 * @param 操做內容描述
	 */
	String option();
	
	/**
	 * @param TerminalConstantClass.SYS__OPTIONLEVEL_0 = "common"(通常操做,記錄保留時間短) 
	 * @param TerminalConstantClass.SYS__OPTIONLEVEL_1 = "sensitive"(敏感操做,記錄保留時間長)
	 */
	String optionLevel();
}

 

同時在定義的切面類指定切入點apache

@Pointcut(value = "within(com.ustcinfo.fccos.terminal.web..*) && @annotation(com.ustcinfo.fccos.terminal.web.AOP.logAnnotation)")
	public void operationLogcontrollerAspect() {
	}

表明的是web目錄下全部子文件夾註解類型爲logAnnotation 均是切入點session

 

定義切入點行爲日誌

@Before(value = "operationLogcontrollerAspect() && @annotation(log)")
	public void doBefore(JoinPoint joinPoint,logAnnotation log) {
		System.out.println("****************");
		try {
			HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
			String ip = request.getRemoteAddr();
			HttpSession session = request.getSession();
			LoginUserRightsModel loginUser = getLoginInfos(session);
			String userId = loginUser.getUserId();
			System.out.println(joinPoint.getSignature().getName());
			System.out.println(log.option());
			System.out.println("目標方法內的參數爲" + Arrays.asList(joinPoint.getArgs()));
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("記錄操做日誌發生異常:\n" + e.getMessage());
		}
	}

joinPoint.getArgs()---------獲取請求的入參信息code

log.option()--------獲取註解自定義屬性中的 option內容ip

joinPoint.getSignature().getName()-----獲取註解的方法名。。。。。ci

 

2018-05-09 14:22:16.101 INFO  [MyFilter] 當前admin用戶id:3--3
2018-05-09 14:22:16.102 INFO  [MyFilter] 查找權限信息
2018-05-09 14:22:16.109 INFO  [MyFilter] 找到對應的權限配置信息,admin--[LoginUserRightsModel [userId=admin, isGodownManage=false, proviceCode=80001, cityName=安徽省, cityCode=80001, countyName=null, countyCode=80001, godownCodeM=null, godownNameM=null, godownLevelM=null, godownTypeM=null, level=省級, godownDpt=null]]
****************
getInstallerInfos
查詢具體裝維的歸屬信息
目標方法內的參數爲[AA150]
2018-05-09 14:22:16.185 DEBUG [getInfosByuserId] ==>  Preparing: SELECT `user_id`,`user_name`,`region_id`,`region_name`,`county_id`,`county_name`,`potrolgroup_id`,`potrolgroup_name` FROM device2.`tb_usrgrp_rela` WHERE `user_id`=? 
2018-05-09 14:22:16.213 DEBUG [getInfosByuserId] ==> Parameters: AA150(String)
2018-05-09 14:22:16.253 DEBUG [getInfosByuserId] <==      Total: 1

以上是切面日誌信息terminal

相關文章
相關標籤/搜索