各种Spring MVC RequestMapping配置问题 [英] Various Spring MVC RequestMapping configuration questions
问题描述
关于Spring MVC RequestMapping配置,我有几个(尽管相关)问题:
I have several (albeit related) questions about Spring MVC RequestMapping configuration:
- 说我有一个类型级别的RequestMapping注释,如下所示:
@RequestMapping("/root/")
.添加此方法级别的RequestMapping:@RequestMapping(value="leaf")
和那个方法级:@RequestMapping(value="/leaf")
有什么区别?注意第二个方法级映射中的前导斜杠. - 拥有此类型级别的RequestMapping:
@RequestMapping("/root/")
和那个@RequestMapping("/root/*")
有什么区别?请注意第二个映射中的星星. - 说我已经有一个类型级别的RequestMapping注释.如何在方法级别覆盖类型级别的映射,以便忽略类型级别的映射(对于给定的控制器)?
- Say I have a type-level RequestMapping annotation as follows:
@RequestMapping("/root/")
. What is the difference between adding this method-level RequestMapping:@RequestMapping(value="leaf")
and that one:@RequestMapping(value="/leaf")
? Notice the leading slash in second method-level mapping. - What is the difference between having this type-level RequestMapping:
@RequestMapping("/root/")
and that one@RequestMapping("/root/*")
? Notice the star in second mapping. - Say I already have a type-level RequestMapping annotation. How do I override the type-level mapping at the method-level so that the type-level mapping is ignored (for a given controller)?
推荐答案
-
这两种情况下的映射都应该相同-两种方法级映射的
/root/leaf
两者相同,在两种情况下,类型级别映射将与方法级别映射结合以生成完整的请求路径,因此具有方法映射的
/root/*
的类型级别将变为/root/leaf
-更多规则在这里- http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/util/AntPathMatcher.html#combine(java.lang.String ,java .lang.String)Both are same, in both cases the type level mapping will be combined with the method level mapping to generate the full request path, so type level of
/root/*
with the method mapping will become/root/leaf
- more rules are here - http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/util/AntPathMatcher.html#combine(java.lang.String, java.lang.String)我怀疑是否可以将类型级别映射与方法级别映射结合起来以创建完整路径.
I doubt if you can, type level mapping is combined with method level mapping to create the full path.
这篇关于各种Spring MVC RequestMapping配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!