JSP custom annotations and operation logs, jsp custom annotation logs

Source: Internet
Author: User

JSP custom annotations and operation logs, jsp custom annotation logs

JSP custom annotation and operation Logging

Spring configuration file

<aop:aspectj-autoproxy />

Log interceptor

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 () {}/ *** the surround notification is used to intercept specified content and record user operations */@ Around (value =" aApplogic () & @ annotation (annotation) & args (object ,..) ", argNames =" annotation, object ") public void interceptorApplogic (ProceedingJoinPoint joinPoint, BussAnnotation annotation, Object object) throws Throwable {System. out. println ("module name moduleName:" + annotation. moduleName (); System. out. println ("Operation name option:" + annotation. option (); String methodName = joinPoint. getSignature (). getName (); System. out. println ("method name methodName:" + methodName); MethodSignature methodSignature = (MethodSignature) joinPoint. getSignature (); String [] strings = methodSignature. getParameterNames (); joinPoint. proceed (); Object [] arguments = joinPoint. getArgs (); // obtain the parameter list if (arguments. length <= 0) {System. out. println (methodName + "method has no parameter");} else {for (int I = 0; I <arguments. length; I ++) {System. out. println (strings [I] + ":" + arguments [I] + ":");}}}}

Custom Annotation

@ Retention (RetentionPolicy. RUNTIME) @ Target ({ElementType. METHOD}) @ brief ented public @ interface BussAnnotation {// Module name String moduleName () default ""; // operation content String option () default "";}

Interface implementation

Written in service

@ BussAnnotation (moduleName = "Personnel Management", option = "Add User") public void testDemo1 (PageData pd) throws Exception {}

Junit testing class

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(); }  } }  

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.