• spring注解的简单使用打印接口信息


    package dhht.seal.hn.gate.config;

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;

    /**
    * @author sh
    */
    @Target({ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface ApiInfoAnnotion {
    String name() default "";

    String version() default "";
    }

    package dhht.seal.hn.gate.config;

    import dhht.seal.hn.gate.util.VersionInfo;
    import dhht.seal.hn.gate.vo.ResultVO;
    import lombok.extern.slf4j.Slf4j;
    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 java.lang.reflect.Method;

    /**
    * @Author: sh
    * @Description:
    * @Version:
    * @Date: 2020/12/28
    */
    @Slf4j
    @Component
    @Aspect
    public class ApiInfoControllerAop {

    @Pointcut("execution(* dhht.seal.hn.gate..*Controller.*(..))")
    public void pointCut() {
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) {
    String name = "";
    try {
    Class<?> aClass = joinPoint.getTarget().getClass();
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method declaredMethod = aClass.getDeclaredMethod(signature.getName(), signature.getParameterTypes());
    ApiInfoAnnotion annotation = declaredMethod.getAnnotation(ApiInfoAnnotion.class);
    boolean bl = (null != annotation);
    if (bl) {
    name = annotation.name();
    log.info("===start opt===" + name + "===version" + VersionInfo.VERION);
    }
    //return joinPoint.proceed();
    Object proceed = joinPoint.proceed();
    if (bl) {
    log.info("===end opt===" + name + "===version" + VersionInfo.VERION);
    }
    return proceed;
    } catch (Throwable throwable) {
    log.error(throwable.getMessage());
    log.error("===end opt===" + name + "===version" + VersionInfo.VERION);
    return ResultVO.fail(throwable.getMessage(), null);
    }
    }
    }

    @ApiInfoAnnotion(name = "用章单位备案")
    @PostMapping(value = "approval", produces = "application/json;charset=UTF-8", name = "用章单位备案")
    public ResultVO approval(@RequestBody @Valid ReqCropApprovalVO data, BindingResult bindingResult) {
    ResultVO resultVO = cropService.cropApproval(data);
    return resultVO;
    }


  • 相关阅读:
    Mybatis源代码分析之类型转换
    eclipse中对于@override注解的函数报父类没有该方法
    Mybatis源代码分析之metadata包
    Android GC
    有道单词本导出xml转换.
    广播的接收与U盘广播
    Bitmap和Drawable相互转换方法
    如何提交程序到Android Market
    error parsing xml:unbound prefix
    android获取屏幕尺寸、密度
  • 原文地址:https://www.cnblogs.com/sung1024/p/15594109.html
Copyright © 2020-2023  润新知