• spring mvc-获取 @resposeBody


    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.core.MethodParameter;
    import org.springframework.http.MediaType;
    import org.springframework.http.converter.HttpMessageConverter;
    import org.springframework.http.server.ServerHttpRequest;
    import org.springframework.http.server.ServerHttpResponse;
    import org.springframework.http.server.ServletServerHttpRequest;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
    
    import cc.xxxxx.common.retus.ReturnMsg;
    
    /**
     * 日志跟踪记录接口参数及返回状态
     * 
     * @fileName CatResponseBodyAdvice.java
     * @Description
     * @author light-zhang
     * @date 2018年6月26日下午2:55:55
     * @version 1.0.0
     */
    @Controller
    @ControllerAdvice
    public class CatResponseBodyAdvice implements ResponseBodyAdvice<ReturnMsg<?>> {
    
        private static final Logger logger = LoggerFactory.getLogger(CatResponseBodyAdvice.class);
        
        private static ServletServerHttpRequest servletRequest;
    
        @Override
        public ReturnMsg<?> beforeBodyWrite(ReturnMsg<?> arg0, MethodParameter arg1, MediaType arg2,
                Class<? extends HttpMessageConverter<?>> arg3, ServerHttpRequest arg4, ServerHttpResponse arg5) {
            servletRequest = (ServletServerHttpRequest) arg4;
            logger.info("访问者ip地址信息:{}", arg4.getRemoteAddress().getHostString());
            logger.info("协议{},方式:{},请求地址信息:{}", arg4.getURI().getScheme(), arg4.getMethodValue(),
                    arg4.getURI().toASCIIString());
            logger.info("请求CLASS-路径信息:{}", arg1.getExecutable().getDeclaringClass().getName());
            logger.info("请求函数名称:{},请求媒体类型信息:{}", arg1.getExecutable().getName(), arg2.toString());
            logger.info("请求参数信息:{}", servletRequest.getServletRequest().getParameterMap());
            logger.info("响应参数信息:{}", arg0);
            return arg0;
        }
    
        @Override
        public boolean supports(MethodParameter arg0, Class<? extends HttpMessageConverter<?>> arg1) {
            return true;
        }
    }
  • 相关阅读:
    自用python时间格式转换lib库代码
    如何在datetime.strptime中添加时区
    bs3迁移到bs4, import lxml.html.soupparser 报错的解决
    mac下pip install lxml报错
    删除 Mac OS 10.10 中“打开方式”里重复或无用的程序列表
    python的urllib2库详细使用说明
    近期个人项目计划
    在centos中添加freeswitch服务开机自动运行
    ddd
    Sqlserver 2008安装
  • 原文地址:https://www.cnblogs.com/light-zhang/p/9229780.html
Copyright © 2020-2023  润新知