如何在Spring MVC控制器的@RequestMapping路径中限制路由扩展? [英] How do I restrict route extensions in @RequestMapping paths for Spring MVC controllers?
问题描述
我有一个很想完成的任务,但是似乎找不到有关Spring MVC路由的信息。我有一个非常简单的控制器,可将路径路由到视图:
I have a fairly simple task that I want to accomplish, but can't seem to find information for Spring MVC routing about it. I have a very simple controller that routes a path to a view:
@Controller
@RequestMapping(value = "/help")
public class HelpController {
private static final String HELP = "help";
@RequestMapping(method = RequestMethod.GET)
public String help(Model model, Locale locale) {
model.addAttribute("locale", locale);
return HELP;
}
}
如果我想抛出404 http://mysite.com/help.some.extension.is.entered ,但是Spring似乎将示例解析为/ help。 javadoc表示@RequestMapping批注只是一个servlet URI映射,但我认为/ help表示它必须完全匹配。
I would like to throw a 404 if http://mysite.com/help.some.extension.is.entered, but Spring seems to resolve the example to /help. The javadoc says that the @RequestMapping annotation is just a servlet URI mapping, but I thought /help means it needs to be an exact match. Any clarification would be appreciated.
推荐答案
对于Spring 4,解决起来很容易:
For Spring 4 it's pretty easy to solve:
<mvc:annotation-driven>
<mvc:path-matching suffix-pattern="false" />
</mvc:annotation-driven>
所以您仍然可以使用 mvc:注释驱动
作为您的配置。
So you still can use mvc:annotation-driven
for your config.
这篇关于如何在Spring MVC控制器的@RequestMapping路径中限制路由扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!