import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import java.lang.reflect.Method;
@Component
@Aspect
public class MvcMethodLogAdvice { private static Logger log = LoggerFactory.getLogger(MvcMethodLogAdvice.class); @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable { Object args[] = joinPoint.getArgs();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
// join arguments.
log.info("{}.{} : 请求参数:{} ", method.getDeclaringClass().getName(), method.getName(), StringUtils.join(args, " ; "));
long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long timeConsuming = System.currentTimeMillis() - start;
log.info("调用结束--> 返回值:{} 耗时:{}ms", JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue), timeConsuming);
return result;
}
}

在你的项目中加入这个类就好,这样设置之后,就会打印这样的日志

对日后定位问题极有助益

spring MVC模式拦截所有入口方法的入参出参打印的更多相关文章

  1. Spring mvc 模式小结

    http://www.taobaotesting.com/blogs/2375 1.spring mvc简介 Spring MVC框架是一个MVC框架,通过实现Model-View-Controlle ...

  2. spring mvc +cookie+拦截器功能 实现系统自动登陆

    先看看我遇到的问题: @ResponseBody @RequestMapping("/logout") public Json logout(HttpSession session ...

  3. 玩转spring MVC(七)----拦截器

    继续在前边的基础上来学习spring MVC中拦截器的使用,下面通过一个例子来实现(完整项目在这里下载:http://download.csdn.net/detail/u012116457/84334 ...

  4. Spring mvc登录拦截器

    自己实现的第一个Spring mvc登录拦截器 题目要求:拒绝未登录用户进入系统,只要发现用户未登录,则将用户请求转发到/login.do要求用户登录 实现步骤: 1.在spring的配置文件中添加登 ...

  5. Spring MVC 跳转页面的方法

    转一个Spring MVC 跳转页面的方法,楼主总结的很全面,留着备用. https://blog.csdn.net/c_royi/article/details/78528758

  6. 基于Spring MVC 实现拦截器

    Spring MVC 拦截器 一,具体内容: 在所有的开发之中拦截器属于一个重要的组件,可以说几乎所有的项目都会提供的概念应用,不管是Spring MVC,还是Struts 2.x都是提供有拦截器的, ...

  7. [Spring MVC] - Interceptor 拦截器

    Spring MVC中的Interceptor与Struts2的差不多. 下面是一个简单的Interceptor登陆验证例子: 1.需要在spring的配置文件中加入这段: <!-- 自定义拦截 ...

  8. spring mvc 配置文件拦截器过滤url

    最近在用spring mvc拦截器,sprin 版本号4.0.6.RELEASE, <mvc:interceptor> <mvc:mapping path="/admin/ ...

  9. Spring MVC定义拦截器

    拦截器: package sy.Interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http ...

随机推荐

  1. Tomcat最大连接数问题

    Tomcat的server.xml中Context元素的以下参数应该怎么配合适 <Connector port="8080" maxThreads="150&quo ...

  2. 从wiresharp看tcp三次握手

    我们知道,传输层是OSI模型中用户进行数据传输的分层,目前仅有TCP和UDP两种协议可用.TCP为了进行传输控制,引入了三次握手机制,以确保通信连接的建立.道理很简单,我们跟别人打电话聊天时,对方拿起 ...

  3. 【转载】最短路径—Dijkstra算法和Floyd算法

    注意:以下代码 只是描述思路,没有测试过!! Dijkstra算法 1.定义概览 Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始 ...

  4. vs2015安装ORACLE的DbFirst

    不说DbFirst好在哪里,它和ModelFirst,CodeFirst都各有各的好,由于对于已经存在的一个大型的业务库,使用EntityFramework的更倾向于DbFirst,因为好多同事已经习 ...

  5. GOF23设计模式之装饰模式(decorator)

    一.装饰模式概述 (1)动态的为一个对象增加新的功能. (2)装饰模式是一种用于代替继承的技术,无需通过继承增加子类就能扩展对象的新功能.   使用对象的关联关系代替继承关系,更加灵活,同时避免类型体 ...

  6. python 发红包

    import random li = [] def fahongbao(money,num=6): if money > 0 and num != 1: n = round(random.uni ...

  7. python学习 (三十四) Python文件操作

    1 写文件 my_list = ["] my_file = open("myfile.txt", "w") for item in my_list: ...

  8. 在线pubmed

    ESearch(文本搜索) eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi http://eutils.ncbi.nlm.nih.gov/entr ...

  9. Sqlmap用法小结

    一共有七个等级0.只显示python错误以及严重的信息.1.同时显示基本信息和警告信息.(默认)2.同时显示debug信息.3.同时显示注入的payload.4.同时显示HTTP请求.5.同时显示HT ...

  10. python开发_python中的range()函数

    python中的range()函数的功能hen强大,所以我觉得很有必要和大家分享一下 就好像其API中所描述的: If you do need to iterate over a sequence o ...