spring mvc - Whats the use of mapping @requestMapping onto an entire class? -


this extremely basic question spring mvc have seen few examples @requestmapping sits above class name of controller :

@requestmapping     public class somethingcontroller {     .     .     . } 

i understan use of requestmapping when comes methods haven't been able understand use of mapping onto entire class. used for?

thanks in advance.

it allows mapping methods url, or url prefix, or other restrictions. further restrictions (like post/get, or url suffix, etc.) can defined requestmapping annotation on methods. these method-level restrictions either complement or override restrictions placed on type-level annotation.

the attributes can used @ class or method or both levels, , how behave, specified in the javadoc.

for example:

@requestmapping(value = "/foo", produces = "test/html") public class somecontroller {      @requestmapping(method = requestmethod.get)     public string method1() {         ...     }      @requestmapping(method = requestmethod.post)     public string method1() {         ...     } } 

in example, both methods mapped on /foo , produce html, first 1 called when http method get, whereas second 1 called when http method post.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -