@Component
public class Interceptor implements HandlerInterceptor {
public static Logger log = LoggerFactory.getLogger(Interceptor.class);
// 在Controller方法执行前被执行
// 登入拦截、权限认证等等
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type,Access-Token");
response.setHeader("Access-Control-Expose-Headers", "*");
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
String requestURI = request.getRequestURI();
log.info("请求地址:"+requestURI);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
throws Exception {
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
throws Exception {
}
}