新增日志配置,分页新增sql方法
This commit is contained in:
Binary file not shown.
@@ -54,4 +54,8 @@ public class WebPageInfo implements Serializable {
|
|||||||
public static boolean hasSort(WebPageInfo webPageInfo) {
|
public static boolean hasSort(WebPageInfo webPageInfo) {
|
||||||
return !StringUtils.isBlank(webPageInfo.getSortField());
|
return !StringUtils.isBlank(webPageInfo.getSortField());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSortSql() {
|
||||||
|
return this.sortField + " " + this.order;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.aspectj.lang.annotation.Before;
|
|||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
@@ -21,39 +22,44 @@ import java.util.Enumeration;
|
|||||||
@Component
|
@Component
|
||||||
public class WebPatternlLog {
|
public class WebPatternlLog {
|
||||||
|
|
||||||
|
@Value("${show-controller-log}")
|
||||||
|
public boolean flag;
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(WebPatternlLog.class);
|
private final static Logger logger = LoggerFactory.getLogger(WebPatternlLog.class);
|
||||||
|
|
||||||
//这个切点的表达式需要根据自己的项目来写
|
//这个切点的表达式需要根据自己的项目来写
|
||||||
@Pointcut("execution(public * com.common.base.controller..*(..))")
|
@Pointcut("execution(public * com..*.controller..*(..))")
|
||||||
public void log() {
|
public void log() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before("log()")
|
@Before("log()")
|
||||||
public void doBefore(JoinPoint joinPoint) {
|
public void doBefore(JoinPoint joinPoint) {
|
||||||
//logger.info("aop doBefore..");
|
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
||||||
HttpServletRequest request = attributes.getRequest();
|
|
||||||
|
|
||||||
//url
|
if (flag) {
|
||||||
logger.info("url={}", request.getRequestURI());
|
//logger.info("aop doBefore..");
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
|
||||||
//method
|
//url
|
||||||
logger.info("method={}", request.getMethod());
|
logger.info("url={}", request.getRequestURI());
|
||||||
|
|
||||||
//ip
|
//method
|
||||||
logger.info("ip={}", request.getRemoteAddr());
|
logger.info("method={}", request.getMethod());
|
||||||
|
|
||||||
//类方法
|
//ip
|
||||||
logger.info("classMethod={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
|
logger.info("ip={}", request.getRemoteAddr());
|
||||||
|
|
||||||
//参数
|
//类方法
|
||||||
Enumeration<String> paramter = request.getParameterNames();
|
logger.info("classMethod={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
|
||||||
while (paramter.hasMoreElements()) {
|
|
||||||
String str = (String) paramter.nextElement();
|
//参数
|
||||||
logger.info(str + "={}", request.getParameter(str));
|
Enumeration<String> paramter = request.getParameterNames();
|
||||||
|
while (paramter.hasMoreElements()) {
|
||||||
|
String str = (String) paramter.nextElement();
|
||||||
|
logger.info(str + "={}", request.getParameter(str));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After("log()")
|
@After("log()")
|
||||||
|
|||||||
Reference in New Issue
Block a user