admin管理员组

文章数量:1794759

spring boot之spring mvc路径匹配

spring boot之spring mvc路径匹配

  • springboot目录

第一种方式
  • 第一步,application.yml添加如下配置,use-suffix-pattern的作用是将www/ww.xx的链接同www/ww等价,配置完后会在匹配servlet时将.xx自动忽略
spring: mvc: pathmatch: use-suffix-pattern: false # use-registered-suffix-pattern: true #默认为false,同use-suffix-pattern作用一致,但仅支持第二步注册过的后缀,这样更安全 contentnegotiation: favor-path-extension: false # 不知道什么意思
  • 第二步,添加过滤器,过滤指定后缀链接,如下只允许.do的链接通过
@SpringBootApplication @ServletComponentScan public class JtiismUwpWebApplication { public static void main(String[] args) { SpringApplication.run(JtiismUwpWebApplication.class, args); } @Bean public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) { ServletRegistrationBean<DispatcherServlet> servletServletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet); servletServletRegistrationBean.addUrlMappings("*.do"); return servletServletRegistrationBean; } } 第二种方式
  • 第一步,添加配置类
@Configuration public class MyWebMvcConfigurer implements WebMvcConfigurer { @Override public void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) { pathMatchConfigurer.setUseSuffixPatternMatch(false); //将www/ww.xx的链接同www/ww等价,配置完后会在匹配servlet时将.xx自动忽略 pathMatchConfigurer.setUseRegisteredSuffixPatternMatch(true); } @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false); } }
  • 第二步,同第一种方式

本文标签: 路径springbootMVC