在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java  網(wǎng)絡(luò)安全/ struts2 ActionInvocation 獲取不到注解的值,麻煩各位幫忙

struts2 ActionInvocation 獲取不到注解的值,麻煩各位幫忙看下?

注解

/**
 * 系統(tǒng)日志注解
 *
 * @author linyuting
 * @since 2018-3-13
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SysLogAnnotation {

    String value() default "";
}

攔截器

    @Override
    public String intercept(ActionInvocation ai)
        throws Exception
    {
        try
        {
            String methodName = ai.getProxy().getMethod();
            Method currentMethod = ai.getAction().getClass().getMethod(methodName, null);
            if (currentMethod.isAnnotationPresent(SysLogAnnotation.class))
            {
                SysLogAnnotation sysLogAnnotation = currentMethod.getAnnotation(SysLogAnnotation.class);
                if (sysLogAnnotation != null)
                {
                    StringUtil.log(sysLogAnnotation.value());
                }
            }

            StringUtil.log(StringUtil.log(new Date()));
            SysLogin user = (SysLogin)SecurityUtils.getSubject().getPrincipal();
            if (user != null)
            {
                StringUtil.log("操作人:" + user.getName());
            }
            else
            {
                StringUtil.log("操作人:系統(tǒng)未獲取");
            }
            StringUtil.log("類名:" + ai.getAction() + " ");
            StringUtil.log("方法名:" + ai.getInvocationContext().getName() + " ");
            Map<String, Object> map = ai.getInvocationContext().getParameters();
            Set<String> keys = map.keySet();
            StringUtil.log("參數(shù):");
            for (String key : keys)
            {
                StringUtil.log(key + "=" + ((Object[])map.get(key))[0] + "#");
            }
            StringUtil.log(" ");
            StringUtil.log("執(zhí)行結(jié)果:" + ai.getResultCode() + " ");
            // SysLog syslog = new SysLog();
            // sysLogService.insert(syslog);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return ai.invoke();
    }
回答
編輯回答
空痕

這個(gè)是因?yàn)閟pring的動(dòng)態(tài)代理,把class去掉動(dòng)態(tài)代理那塊字符串,再轉(zhuǎn)成類就能獲取到注解了.

2017年9月14日 09:02