AOP中获取controller层 json参数

package com.ck.framework.basicframework.aop;

import cn.hutool.core.bean.BeanUtil;
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.springframework.stereotype.Component;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Create By Cuixk
 * 2019/7/2 10:29
 */
@Slf4j
@Aspect
@Component
public class ResultResponseAspect {

    @Pointcut("execution(public * com.ck.framework.basicframework.controller.*.*(..))")
    public void webPointCut() {

    }

    @Around(value = "webPointCut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {

        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            HttpServletRequest httpServletRequest = BeanUtil.toBean(arg,HttpServletRequest.class);
            ServletInputStream inputStream = httpServletRequest.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder requestBuilder = new StringBuilder();
            String inputStr;
            while ((inputStr = reader.readLine()) != null) {
                requestBuilder.append(inputStr);
            }
            System.out.println(requestBuilder.toString());
        }
        return pjp.proceed();

    }
}

你可能感兴趣的:(java)