1. User management business logic Interface (Usermanagerapplogic.java) Java code package com.iteye.applogic; Public interface Usermanagerapplogic {public void AddUser (String name); }
2.&NBSP User management business logic implementation Class (Usermanagerapplogicimpl.java) Java code package com.iteye.applogic.impl; import org.springframework.stereotype.component; import com.iteye.applogic.usermanagerapplogic; import com.iteye.annotation.bussannotation; @Component ("Usermanager") Public class UserManagerApplogicImpl implements UserManagerApplogic { @BussAnnotation (modulename= "People Management", option= "Add user") public void adduser (string name) { System.out.println ("add a user! name is "+name"; } }
3. Business Annotation Class (Busannotation.java) Java code package com.iteye.annotation; Import Java.lang.annotation.ElementType; Import java.lang.annotation.Retention; Import Java.lang.annotation.RetentionPolicy; Import Java.lang.annotation.Target; @Retention (Retentionpolicy.runtime) @Target ({Elementtype.method}) public @interface bussannotation {//module name String ModuleName (); Action content String option (); }
(1) The Retentionpolicy (retention policy) is an enum type with a total of three values, Source,class and RUNTIME respectively.
Source represents the annotation type of information will only remain in the program source code, if the source code is compiled, the annotation data will disappear, and will not be kept in the compiled. class file.
class represents that the annotation type of information is retained in the source code of the program, but it is also kept in the compiled. class file, and does not load this information into the virtual machine (JVM) at the time of execution. . Note that when you do not set a annotation type of retention value, the system default is class.
runtime represents the retention of information in the source code, compiled. class file, which loads the information into the JVM when it is executed.
(2) ElementType
The ElementType inside the @target is used to specify which elements the annotation type can be used on.
Type is the type that can be used on class,interface,enum and annotation types.
FIELD (properties)
Method (Methods)
PARAMETER (Parameters)
Constructor (constructors)
local_variable (local variable)
Annotation_type
PACKAGE (Package)
(3) @Documented
The purpose of @Documented is to allow this type of annotation information to be displayed on the JAVAAPI documentation; If not added, the information generated by this type will not be found when using Javadoc to generate API documents.
(4) @Inherited
If you need to inherit the annotation data to the subclass, you will use the @inherited annotation type.
4. Slice class (Loginterceptor.java) Java code package COM.ITEYE.AOP; Import Org.aspectj.lang.ProceedingJoinPoint; Import Org.aspectj.lang.annotation.Around; Import Org.aspectj.lang.annotation.Aspect; Import Org.aspectj.lang.annotation.Pointcut;