新增日志配置,分页新增sql方法

This commit is contained in:
haoqiong liu
2020-09-22 13:45:27 +08:00
parent bc9e488680
commit 54188fcec7
3 changed files with 28 additions and 18 deletions

Binary file not shown.

View File

@@ -54,4 +54,8 @@ public class WebPageInfo implements Serializable {
public static boolean hasSort(WebPageInfo webPageInfo) {
return !StringUtils.isBlank(webPageInfo.getSortField());
}
public String getSortSql() {
return this.sortField + " " + this.order;
}
}

View File

@@ -7,6 +7,7 @@ import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -21,39 +22,44 @@ import java.util.Enumeration;
@Component
public class WebPatternlLog {
@Value("${show-controller-log}")
public boolean flag;
private final static Logger logger = LoggerFactory.getLogger(WebPatternlLog.class);
//这个切点的表达式需要根据自己的项目来写
@Pointcut("execution(public * com.common.base.controller..*(..))")
@Pointcut("execution(public * com..*.controller..*(..))")
public void log() {
}
@Before("log()")
public void doBefore(JoinPoint joinPoint) {
//logger.info("aop doBefore..");
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//url
logger.info("url={}", request.getRequestURI());
if (flag) {
//logger.info("aop doBefore..");
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//method
logger.info("method={}", request.getMethod());
//url
logger.info("url={}", request.getRequestURI());
//ip
logger.info("ip={}", request.getRemoteAddr());
//method
logger.info("method={}", request.getMethod());
//类方法
logger.info("classMethod={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//ip
logger.info("ip={}", request.getRemoteAddr());
//参数
Enumeration<String> paramter = request.getParameterNames();
while (paramter.hasMoreElements()) {
String str = (String) paramter.nextElement();
logger.info(str + "={}", request.getParameter(str));
//类方法
logger.info("classMethod={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//参数
Enumeration<String> paramter = request.getParameterNames();
while (paramter.hasMoreElements()) {
String str = (String) paramter.nextElement();
logger.info(str + "={}", request.getParameter(str));
}
}
}
@After("log()")