[英]Spring Boot 2.6.7 URL case insensitive configuration
在 Spring Boot 2.6.7 中,我想将所有控制器的 URL 设置为不区分大小写。
我试过了,但它不起作用
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
AntPathMatcher matcher = new AntPathMatcher();
matcher.setCaseSensitive(false);
configurer.setPathMatcher(matcher);
}
}
我们可以通过 application.properties 文件来配置它吗?
根据文档AntPathMatcher Documentation , setCaseSensitive
的布尔值应该为false
以获得不区分大小写的行为。
所以更换
matcher.setCaseSensitive(true);
经过
matcher.setCaseSensitive(false);
在@Xiidref 解决方案之后,您可以添加
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
在您的application.properties
文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.