开发者

How many spring controller in spring3

开发者 https://www.devze.com 2023-03-03 08:20 出处:网络
I want to know that how many number开发者_如何学JAVAs of controllers in spring3. i am new in spring waiting for your response

I want to know that how many number开发者_如何学JAVAs of controllers in spring3. i am new in spring waiting for your response

Thanks


You can have as much controllers as you want. You can configure it the following way:

In Your xml add the following:

<context:annotation-config />
<context:component-scan base-package="com.vanilla.controllers" />

Now you need to mark all classes in package com.vanilla.controllers.* with @Controller annotation

Example:

package com.vanilla.controllers;

@Controller
@RequestMapping(value="/admin")
public class AdminController {

    @RequestMapping(value="/login.html", method=RequestMethod.GET)
    public ModelAndView index(){
        Admin admin = new Admin();
        ModelAndView mv = new ModelAndView("admin/index");
        mv.addObject("admin", admin);
        return mv;
    }

}

Or another Example:

 package com.vanilla.controllers;
@Controller
public class DefaultController {

    @RequestMapping(value="/index.html", method=RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("index");
        return mv;
    }

}

That way you can use as much controllers as you want.


As per Spring 3.O doc's only 20 controllers are in SpringMVC

 1. AbstractCommandController
 2. AbstractController
 3. AbstractFormController
 4. AbstractUrlViewController
 5. AbstractWizardFormController
 6. BaseCommandController
 7. CancellableFormController
 8. ComponentControllerSupport
 9. Controller
 10. EventAwareController
 11. MultiActionController
 12. ParameterizableViewController
 13. PortletModeNameViewController
 14. PortletWrappingController
 15. ResourceAwareController
 16. ServletForwardingController
 17. ServletWrappingController
 18. SimpleControllerHandlerAdapter
 19. SimpleFormController
 20. UrlFilenameViewController


I'm still a Sprint N00b, so take my opinions with salt.

There is no simple answer to this question. The simplest answer is, "as many as you need".

Spring has no hard coded limit to the number of controllers that your application can use, but from a complexity point of view, if you have more than 100 controllers, you probably have "way too many" controllers.

I like one controller per "thing" and I define "thing" as a collection of closeley related functionality. I might have 4 or more view pages per "thing" but they are all to support the same functionality.


You can create as many as controller you liked in Spring MVC .

So , do you mean the built-in Controllers provided by Spring MVC (likes ParameterizableViewController , SimpleFormController etc )? You can refer to the spring 3.0 api for all the implementing Controller provided by Spring .However , many of them are deprecated since version 3.0 , as they are replaced by annotated controllers

0

精彩评论

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