java – 为什么控制器中的@RequestMapping Spring注释会捕获更多
发布时间:2020-12-15 04:27:42 所属栏目:Java 来源:网络整理
导读:我有简单的 Spring控制器与映射: @Controllerpublic class HomeController {@RequestMapping(value = "/home",method = RequestMethod.GET) public String home(HttpSession session,HttpServletRequest request,HttpServletResponse response,Model Princi
我有简单的
Spring控制器与映射:
@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使用
PathMatchConfigurer 设置MVC环境,其useSuffixPatternMatch设置为true.从
javadoc开始
通过让@Configuration类扩展WebMvcConfigurationSupport并覆盖,可以在MVC配置中将其设置为false @Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch(false); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |