问题描述
我是新来的Spring框架....而上搜索发现google..i在显示水平menthod它已@RequestMapping类级别annoted几个例子和几个例子
I am new to spring framework....while searching on google..i found few examples which has @RequestMapping annoted at the class level and few examples showing it at menthod level
当使用一流水平RequestMapping和menthod水平RequestMapping注解......有谁能够给我解释一下一流水平RequestMapping和方法层面RequestMapping区别??
When to use class level RequestMapping and menthod level RequestMapping annotation...can anybody explain me difference between class level RequestMapping and method level RequestMapping ..??
所以我在
)类级别
b)方法级
另外,我发现了一些 @RequestMapping
类型:GET / POST,而一些例子不具有类型参数
also i found some @Requestmapping
with type :GET/Post,whereas some examples doesn't have type parameter.
哪种方法比较好??
是新版本(> 2.5春季)不需要为请求映射参数类型???
is newer versions(>Spring 2.5) don't need parameter type for request mapping ???
推荐答案
一个控制器必须在类级别标记为 @Controller
。在 @RequestMapping
注释可以在两个类和方法级应用。如果是,方法注释将PTED视为相对URL(相对于类级别的URL)间$ P $。然而,方法级别的注解必须是present,否则该方法将不被映射。
A controller must be marked as @Controller
at the class level. The @RequestMapping
annotation can be applied at both class and method level. If it is, method annotations will be interpreted as relative URLs (relative to the class-level URL). However, method level annotations must be present, otherwise the method won't be mapped.
在注释,参数可以打上默认值可选。该方法的参数是这样一个案例:它默认为 GET
,但可以明确设置为 POST
或别的东西。
In annotations, parameters can be marked as optional with default values. The method parameter is such a case: it defaults to GET
, but can be explicitly set to POST
or something else.
请参阅:
@RequestMapping
- 16.3 Implementing Controllers
这篇关于有谁能够给我解释一下一流水平的控制器和方法液位控制器之间的区别..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!