zoukankan      html  css  js  c++  java
  • spring mvc实现自定义注解

    实现方式:使用@Aspect实现:

    1.

    新建注解接口:CheckSign

    package com.soeasy.web.utils;
    
    import org.springframework.core.Ordered;
    import org.springframework.core.annotation.Order;
    
    import java.lang.annotation.*;
    
    /**
     * Created by Administrator on 2017/10/25 0025.
     */
    @Documented
    @Target({ElementType.METHOD}) //方法上
    @Inherited
    @Retention(RetentionPolicy.RUNTIME) //运行时
    @Order(Ordered.HIGHEST_PRECEDENCE) //最高优先级
    public @interface CheckSign {
    }

    2.

    新建注解实现 CheckSignAspect 类:

    package com.soeasy.web.utils;
    
    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONObject;
    import com.soeasy.commons.FailException;
    import com.soeasy.utils.sign.Des3;
    import com.soeasy.utils.sign.SignConf;
    import org.apache.log4j.Logger;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.springframework.stereotype.Component;
    import java.util.HashMap;
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    /**
     * 自定义注解@CheckSign的实现方法
     * Created by Administrator on 2017/10/25 0025.
     */
    @Aspect
    @Component
    public class CheckSignAspect {
        private Logger log = Logger.getLogger(this.getClass());
        /**
         * 目标方法执行
         * @param pjp
         */
        @Around("@annotation(com.soeasy.web.utils.CheckSign)") //执行@接口
        public Object beforeExec(ProceedingJoinPoint pjp) throws Throwable {
            //获取request信息
            /*RequestAttributes ra = RequestContextHolder.getRequestAttributes();
            ServletRequestAttributes sra = (ServletRequestAttributes)ra;
            HttpServletRequest request = sra.getRequest();*/
    
            //获取post参数
            for (int i = 0; i < pjp.getArgs().length; i++) {
                if(pjp.getArgs()[i] instanceof LinkedHashMap || pjp.getArgs()[i] instanceof JSONObject){
                    Map<String, Object> map = (Map<String,Object>) pjp.getArgs()[i];
    
                }
            }
            return pjp.proceed();
        }
    }
  • 相关阅读:
    Firebird 用查询结果集更新数据,merge
    wcf 登录认证 angular 认证重定向
    WOSA/XFS PTR Form解析库—xfsptrdata.h
    WOSA/XFS PTR Form解析库—头文件
    2019,开启新征程
    VC中添加头文件以及库
    .net4.0多进程间共享内存实现通信(VB.Net)
    共享内存操作类(C#源码)
    VC++ 共享内存读写操作
    c#实现内存映射文件共享内存
  • 原文地址:https://www.cnblogs.com/007sx/p/7749838.html
Copyright © 2011-2022 走看看