Commit 49d5ed5f authored by Quxl's avatar Quxl

x

parent f30aa02a
......@@ -4,11 +4,13 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableAsync
@EnableScheduling
@EnableCaching
@EnableSwagger2
......
package com.egolm.shop.common.interceptor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
@Component
public class LogInterceptor extends HandlerInterceptorAdapter {
@Value("${log.isOpen}")
private Boolean isOpen;
@Value("${log.sProjectID:SHOP}")
private String sProjectID;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
this.exec(req);
return super.preHandle(req, resp, handler);
}
@Autowired
@Qualifier("log")
private JdbcTemplate jdbcTemplate;
private void exec(HttpServletRequest req) {
if(isOpen) {
try {
String contextPath = req.getContextPath();
String uri = req.getRequestURI().substring(contextPath.length());
String remoteIp = ServletUtil.remoteIp(req);
String params = JSON.toJSONString(req.getParameterMap());
Map<String, Object> map = new HashMap<String,Object>();
map.put("sProjectID", sProjectID);
map.put("sURI", uri);
map.put("sClientIP", remoteIp);
map.put("sParams", params);
map.put("dCreateTime", new Date());
jdbcTemplate.save("tLog", map);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
package com.egolm.shop.common.interceptor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
@Component
public class LogInterceptor extends HandlerInterceptorAdapter {
@Value("${log.isOpen}")
private Boolean isOpen;
@Value("${log.sProjectID:SHOP}")
private String sProjectID;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
this.exec(req);
return super.preHandle(req, resp, handler);
}
@Autowired
@Qualifier("log")
private JdbcTemplate jdbcTemplate;
@Async
private void exec(HttpServletRequest req) {
if(isOpen) {
try {
String contextPath = req.getContextPath();
String uri = req.getRequestURI().substring(contextPath.length());
String remoteIp = ServletUtil.remoteIp(req);
String params = JSON.toJSONString(req.getParameterMap());
Map<String, Object> map = new HashMap<String,Object>();
map.put("sProjectID", sProjectID);
map.put("sURI", uri);
map.put("sClientIP", remoteIp);
map.put("sParams", params);
map.put("dCreateTime", new Date());
jdbcTemplate.save("tLog", map);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
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