aop+註解 記錄操作日誌
阿新 • • 發佈:2018-12-18
自定義註解:
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OperateHis {
int operateType() default 0;
}
切面:
@Aspect @Component public class OperateHisAspect { @Pointcut(value = "@annotation(cn.zj.pubinfo.ydd.comm.web.annotation.OperateHis)") private void pointcut() { } @AfterReturning(value = "pointcut() && @annotation(operateHis)", returning = "result") public void afterReturning(JoinPoint point,Object result,OperateHis operateHis) { ShiroUser sUser =null; if (SecurityUtils.getSubject() == null || SecurityUtils.getSubject().getPrincipal() == null) { sUser=null; }else{ sUser=(ShiroUser) SecurityUtils.getSubject().getPrincipal(); String userName = sUser.getUserName(); ExportLog log = new ExportLog(); log.setEx_username(userName); log.setEx_module(operateHis.operateType()); CallServiceUtil.callDataService("exportLogService", "insert", new Object[] { log }, new Class[] { ExportLog.class });// 記錄匯出日誌 } } }
然後在方法上加上註解,如圖:
最後不要忘了在spring配置檔案裡面 加上對於切面類的掃描