Java 为什么控制器中的@RequestMapping Spring注释捕获了更多我想要的内容?
我有一个带有映射的简单Spring控制器:Java 为什么控制器中的@RequestMapping Spring注释捕获了更多我想要的内容?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个带有映射的简单Spring控制器: @Controller public class HomeController { @RequestMapping(value = "/home", method = RequestMethod.GET) public String home(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model Principal princip
@Controller
public class HomeController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model Principal principal) {
...
return "home";
}
}
它捕获http://localhost:18080/XXX/home
,但为什么它会捕获像http://localhost:18080/XXX/home.error
或http://localhost:18080/XXX/home.qwe123.234
等。我没有在任何地方设置home.error或home.qwe123.234等的映射。我的控制器中只有映射。
如何停止控制器与之匹配?因为,在默认情况下,Spring将MVC环境设置为
UseSuffixpatterMatch
设置为true
。从
将模式匹配到时是否使用后缀模式匹配(“*”)
请求。如果启用,则映射到“/users”
的方法也匹配到
“/users.*”
默认值为true
您可以在MVC配置中将其设置为false
,方法是让@configuration
类扩展WebMvcConfigurationSupport
并覆盖
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}
这是正确的。是描述问题的spring文档。