计算机外文翻译---spring的web_mvc_构架模式(编辑修改稿)内容摘要:
, consisting of AbstractController, AbstractCommandController, MultiActionController, SimpleFormController, AbstractWizardFormController. Application controllers will typically be subclasses of those. Note that you can choose an appropriate base class: If you don39。 t have a form, you don39。 t need a FormController. This is a major difference to Struts. You can take any object as mand or form object: There39。 s no need to implement an interface or derive from a base class. Spring39。 s data binding is highly flexible, . it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. So you don39。 t need to duplicate your business objects39。 properties as Strings in your form objects, just to be able to handle invalid submissions, or to convert the Strings properly. Instead, it39。 s often preferable to bind directly to your business objects. This is another major difference to Struts which is built around required base classes like Action and ActionForm for every type of action. Compared to WebWork, Spring has more differentiated object roles: It supports the notion of a Controller, an optional mand or form object, and a model that gets passed to the view. The model will normally include the mand or form object but also arbitrary reference data. Instead, a WebWork Action bines all those roles into one single object. WebWork does allow you to use existing business objects as part of your form, but just by making them bean properties of the respective Action class. Finally, the same Action instance that handles the request gets used for evaluation and form population in the view. Thus, reference data needs to be 10 modelled as bean properties of the Action too. These are arguably too many roles in one object. Regarding views: Spring39。 s view resolution is extremely flexible. A Controller implementation can even write a view directly to the response, returning null as ModelAndView. In the normal case, a ModelAndView instance consists of a view name and a model Map, containing bean names and corresponding objects (like a mand or form, reference data, etc). View name resolution is highly configurable, either via bean names, via a properties file, or via your own ViewResolver implementation. The abstract model Map allows for plete abstraction of the view technology, without any hassle: Be it JSP, Velocity, or anything else every renderer can be integrated directly. The model Map simply gets transformed into an appropriate format, like JSP request attributes or a Velocity template model. 3. Integration: Using a Different Web Framework with Spring Many teams will try to leverage their investments in terms of knowhow and tools, both for existing projects and for new ones. Concretely, there are not only a large number of books and tools for Struts but also a lot of developers that have experience with it. Thus, if you can live with Struts39。 architectural flaws, it can still be a viable choice for the web layer. The same applies to WebWork and other web frameworks. If you don39。 t want to use Spring39。 s web MVC but intend to leverage other solutions that Spring offers, you can integrate the web framework of your choice with Spring easily. Simply start up a Spring root application context via its ContextLoaderListener, and access it via its ServletContext attribute (or Spring39。 s respective helper method) from within a Struts or WebWork action. Note that there aren39。 t any plugins involved, therefore no dedicated integration: From the view of the web layer, you39。 ll simply use Spring as a library, with the root application context instance as entry point. All your registered beans and all of Spring39。 s services can be at your fingertips even without Spring39。 s web MVC. Spring doesn39。 t pete with Struts or WebWork in this usage, it just addresses the many areas that the pure web frameworks don39。 t, from bean configuration to data access and transaction handling. So you are able to enrich your 11 application with a Spring middle tier and/or data access tier, even if you just want to use . the transaction abstraction with JDBC or Hibernate. 4. Feature Check List If just focussing on the web support, some of Spring39。 s unique features are: .Clear separation of roles: controller vs validator vs mand object vs form object vs model object, DispatcherServlet vs handler mapping vs view resolver, etc. .Powerful and straightforward configuration of both framework and application classes as JavaBeans, including easy inbetween referencing via an application context, . from web controllers to business objects and validators. .Adaptability, nonintrusiveness: Use whatever Controller subclass you need (plain, mand, form, wizard, multi action, or a custom one) for a given scenario instead of deriving from Action/ActionForm for everything.。计算机外文翻译---spring的web_mvc_构架模式(编辑修改稿)
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。