版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jm19920911/article/details/80877314
springboot2默认将localhost/test和localhost/test.do认为是2个url
先将localhost/test.*和localhost/test映射到统一方法
@Configuration
public class CustomwebMvcConfigurer implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseRegisteredSuffixPatternMatch(true);
}
}
此时test.*都映射到统一方法上
指定拦截.do
@Bean
public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) {
ServletRegistrationBean<DispatcherServlet> servletServletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet);
servletServletRegistrationBean.addUrlMappings("*.do");
return servletServletRegistrationBean;
}