开发者

Spring MVC: CoC for requesting mapping

Having used other MVC frameworks such as Zend Framework in the past, I am used to the idea of requests being mapped as follows by default.

http://mysite.com/user/add calls the add method in the User controller class, which then calls a view named add, located in a directory named user.

Is 开发者_如何学Cthere a way that I can achieve this (or similar) in Spring MVC 3 rather than using @RequestMapping in my Controller classes and specifying the view to use in each method?


I believe this is possible, but then you're limited by what Spring MVC's convention-over-configuration will do.

I think that the bare minimum is that your controller be annotated with @Controller, and also a class-level @RequestMapping annotation. The individual public methods on that class are then mapped by name. If the methods do not return a view or view name, then the view name will be inferred from the method name.

The documentation doesn't really go into this, though, you're very much encouraged to use method-level annotations, to keep things explicit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜