AspectJ(AOP)切面获取参数名称和参数

  @Async
    @AfterReturning(value ="execution(public * com.zhx.recharge.service.RechargeService.buildOrder(..))", returning = "result")
    public void buildOrder(JoinPoint joinPoint, Object result) throws  Throwable {
        log.info("*****************************************");
        log.info("*****************************************");
        log.info("*****************************************");
        //保存所有请求参数,用于输出到日志中
//        Map allParams = new HashMap();
        /*Object[] paramValues = joinPoint.getArgs();
        String[] paramNames = ((CodeSignature) joinPoint.getSignature()).getParameterNames();
        for(int i=0;i<paramNames.length;i++){
            if (paramValues[i] instanceof Map<?, ?>) {
                //提取方法中的MAP参数,用于记录进日志中
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) paramValues[i];
                allParams.putAll(map);
            }else {
                allParams.put(paramNames[i],paramValues[i]);
            }
        }*/
        Map<String, Object> allParams = (Map<String, Object>) result;
        log.info("this is object={}",allParams);
        String goods_id = String.valueOf(allParams.get("goods_id"));
        String order_no = String.valueOf(allParams.get("order_no"));
        String user_id = String.valueOf(allParams.get("user_id"));
        String uid = String.valueOf(allParams.get("uid"));
        String buy_count = String.valueOf(allParams.get("buy_count"));
        String unitprice= String.valueOf(allParams.get("unitprice"));
        String amount= String.valueOf(allParams.get("amount"));
        String amount_realpay= String.valueOf(allParams.get("amount_realpay"));
        String paygate= String.valueOf(allParams.get("paygate"));
        String goods_priceid= String.valueOf(allParams.get("goods_priceid"));
        String area= String.valueOf(allParams.get("area"));
        String os= String.valueOf(allParams.get("os"));
        String user_ip= String.valueOf(allParams.get("user_ip"));
        String deviceid = String.valueOf(allParams.get("deviceid"));
        String goldcoin = String.valueOf(allParams.get("goldcoin"));
        String flower = String.valueOf(allParams.get("flower"));
        coreWebOrderApi.buildOrder(goods_id,order_no,user_id,uid,buy_count,unitprice,amount,amount_realpay,paygate,goods_priceid,area,os,user_ip,deviceid,goldcoin,flower);
        log.info("success");
        log.info("*****************************************");
        log.info("*****************************************");
    }

 

posted @ 2018-10-11 11:19  748573200000  阅读(5027)  评论(0编辑  收藏  举报