使用自定义注解实现对批量方法使用aop
自定义注解
枚举类型
public enum ResourceType {
DEVICE, LINE, SPECIFIC;
}
自定义注解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ResourceMethod {
ResourceType type() default ResourceType.DEVICE;
}
注解使用
@Override
@ResourceMethod(type = ResourceType.DEVICE)
public PageInfo<JSONObject> queryDeviceById(PageInfo<JSONObject> page) {...}
@Override
@ResourceMethod(type = ResourceType.LINE)
public PageInfo<JSONObject> queryLineById(PageInfo<JSONObject> page) {...}
@Override
@ResourceMethod(type = ResourceType.SPECIFIC)
public PageInfo<JSONObject> querySpecificById(PageInfo<JSONObject> page) {...}
AOP
@Aspect
@Component("OptAspect")
public class OptAspect{
@Around("@annotation(resourceMethod)")
public Object around(ProceedingJoinPoint pj, ResourceMethod resourceMethod) throws Throwable {
PageInfo<JSONObject> pageInfo = (PageInfo<JSONObject>)pj.proceed();
if(type == ResourceType.DEVICE) {
...
}else if(type == ResourceType.LINE) {
...
}else if(type == ResourceType.SPECIFIC) {
...
}
return pageInfo;
}
}