主页 > 知识库 > JSP 自定义注解及记录操作日志

JSP 自定义注解及记录操作日志

热门标签:聊城智能电销机器人外呼 企业怎么在联通申请400电话 南京新思维电话机器人 地图标注市场怎么样 南昌市地图标注app 好操作的电话机器人厂家 如何用中国地图标注数字点 泰州泰兴400电话 怎么申请 百度地图添加标注图标样式

JSP 自定义注解及记录操作日志

Spring的配置文件

aop:aspectj-autoproxy />

日志拦截器

package com.vem.interceptor;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; 
import org.aspectj.lang.annotation.Aspect; 
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import com.vem.entity.BussAnnotation; 

@Aspect 
@Component 
public class LogInterceptor { 
 
 
  @Pointcut("execution(* com.vem.service..*.*(..))") 
  public void aApplogic() { 
   
  } 
   
  /** 
   * 环绕通知 用于拦截指定内容,记录用户的操作 
   */ 
  @Around(value = "aApplogic()  @annotation(annotation) args(object,..) ", argNames = "annotation,object") 
  public void interceptorApplogic(ProceedingJoinPoint joinPoint, 
      BussAnnotation annotation, Object object) throws Throwable { 
    System.out.println("模块名称moduleName:" + annotation.moduleName()); 
    System.out.println("操作名称option:" + annotation.option()); 
    String methodName = joinPoint.getSignature().getName();
 System.out.println("方法名methodName:" + methodName); 
    
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); 
    String[] strings = methodSignature.getParameterNames(); 
    
    joinPoint.proceed(); 
    
    Object[] arguments = joinPoint.getArgs();  //获得参数列表
    if(arguments.length=0){ 
      System.out.println(methodName+"方法没有参数"); 
    }else{ 
     for(int i=0;iarguments.length;i++){ 
     System.out.println(strings[i]+" : "+arguments[i]+" : ");
     } 
    } 
  } 
} 

自定义注解

@Retention(RetentionPolicy.RUNTIME) 
@Target({ElementType.METHOD}) 
@Documented 
public @interface BussAnnotation { 
  //模块名 
  String moduleName() default ""; 
  //操作内容 
  String option() default ""; 
} 

接口实现

写在service

@BussAnnotation(moduleName="人员管理",option="添加用户") 
public void testDemo1(PageData pd) throws Exception{
 
}

junit测试类

package com.vem.entity;

import javax.annotation.Resource;

import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.test.context.ContextConfiguration; 
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.vem.service.data.DemoService;
import com.vem.util.PageData; 
 
@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(
 {"classpath:spring/ApplicationContext.xml"
 })
public class AopTest { 
 
 @Resource(name = "demoService")
 public DemoService demoService;
  
  @Test 
  public void testAopAddUser1(){ 
   PageData pd = new PageData();
   pd.put("name", "zhangzexing");
   pd.put("age", "21");
   pd.put("passward", "123456");
   try {
  demoService.testDemo2(pd);
 } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
  } 

} 
 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:
  • 详解springmvc 中controller与jsp传值
  • springMVC如何将controller中数据传递到jsp页面
  • JSP spring boot / cloud 使用filter防止XSS
  • JSP 获取spring容器中bean的两种方法总结
  • 利用JSP session对象保持住登录状态
  • JSP 开发之 releaseSession的实例详解

标签:自贡 临汾 吉林 开封 乌兰察布 铜川 白银 山南

巨人网络通讯声明:本文标题《JSP 自定义注解及记录操作日志》,本文关键词  JSP,自定义,注解,及,记录,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《JSP 自定义注解及记录操作日志》相关的同类信息!
  • 本页收集关于JSP 自定义注解及记录操作日志的相关信息资讯供网民参考!
  • 推荐文章