Commit d894eda3 by 徐奇

INIT

parent c67c41d5
...@@ -59,6 +59,13 @@ ...@@ -59,6 +59,13 @@
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
<!-- Swagger --> <!-- Swagger -->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
......
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.firstboot.aspect;
import com.alibaba.fastjson.JSON;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@Aspect
@Component
public class HttpAspect {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Pointcut("execution(public * cn.freemud.firstboot.web.*.*(..))")
public void log() {
}
/**
* @Before 在方法执行之前执行
*/
@Before("log()")
public void doBefore(JoinPoint joinPoint) {
//记录http请求
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//从request中获取http请求的url/请求的方法类型/响应该http请求的类方法/IP地址/请求中的参数
logger.info("url={} method={} ip={} class_method={} args_json={}", request.getRequestURI(),
request.getMethod(), request.getRemoteAddr(),
joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(),
JSON.toJSONString(joinPoint.getArgs()));
}
/**
* @After 在方法执行之后执行
*/
@AfterReturning(returning = "object", pointcut = "log()")
public void doAfterReturning(Object object) {
logger.info("response={}", JSON.toJSONString(object));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment