本文介绍了谁能解释一下类级控制器和方法级控制器之间的区别..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 spring 框架的新手....在 google 上搜索时...我发现很少有在类级别注释 @RequestMapping 的示例,也很少有在方法级别显示它的示例

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 和方法级别的 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 ..??

所以我对他们的申请有点困惑:

so I am little bit confused about their application at :

a) 班级

b) 方法级别

我还发现了一些 @Requestmapping 类型为:GET/Post,而一些示例没有类型参数.

Also I found some @Requestmapping with type :GET/Post,whereas some examples doesn't have type parameter.

哪种方法更好..??

新版本(>Spring 2.5)不需要参数类型来进行请求映射???

Is newer versions(>Spring 2.5) don't need parameter type for request mapping ???

推荐答案

控制器必须在类级别标记为 @Controller.@RequestMapping 注释可以应用于类和方法级别.如果是,方法注释将被解释为相对 URL(相对于类级 URL).但是,方法级别的注解必须存在,否则方法将不会被映射.

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.

见:

这篇关于谁能解释一下类级控制器和方法级控制器之间的区别..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 04:15