一、创建MyMvcConfig 继承WebMvcConfigurationSupport
package com.greattao.egtcp.web.foreign.util;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import javax.annotation.Resource;
@Configuration
public class MyMvcConfig extends WebMvcConfigurationSupport {
@Resource
private MyInterCeptor myInterCeptor;
@Override
protected void addInterceptors(InterceptorRegistry registry) {
// addPathPatterns("/**") 表示拦截所有的请求,
// excludePathPatterns("/login", "/register") 表示除了登陆与注册之外,因为登陆注册不需要登陆也可以访问
//注册自己的拦截器,并设置拦截路径,拦截多个可以全一个list集合
registry.addInterceptor(myInterCeptor).addPathPatterns("/**").excludePathPatterns("/actuator/**","/login", "/index");
}
/**
* 配置静态访问资源
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}
二、创建ParameterRequestWrapper 继承HttpServletRequestWrapper
package com.greattao.egtcp.web.foreign.util;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.*;
@Slf4j
public class ParameterRequestWrapper extends HttpServletRequestWrapper {
private Map<String, String[]> params = new HashMap<>();
pri