Development Based on the webwork spring hibernate Project

Source: Internet
Author: User

Development Based on the webwork spring hibernate Project
The combination of the three should be the best java web programming mode.

First, describe their respective roles:

1. hibernate is responsible for database operations

2. spring is responsible for real business operations

3. webwork is responsible for transferring requests and returning spring processing results to users.

In the past development, many people paid attention to the MVC model. Indeed, this pattern divides the program into three parts based on object-oriented thinking. However, in web development, you cannot simply use this mode: the View of web development is fixed (PAGE). After hibernate is introduced, the model is very simple and clear. Control is left, which is a key part of web development. The popular practice is to divide control into two parts: dispacher and business object ). And extract the latter interface, or even share the interface with the model, while truly hiding the logic Implementation of dispacher.

There are many ways to implement this model-view-dispacher-business object Mode. For example, if you create a bo (business object) object, you can directly create a new object or dynamically load it. The factory method is used to abstract the factory. But the best thing is to use spring containers. Dispacher only needs to use the interface. The specific class already has spring AOP injection.

Of course, spring can be well combined with hibernate. You can use DAO or the hibernate template of spring. But this is not important, because your business objects have been completely separated from the call layer. When the business layer needs to deal with hibernate, it is hard to directly create a HibernateUtil. How to do this is no longer the key.

The following describes the combination of spring webwork.

There are three methods of integration in the Wiki doc in webwork (Google query), the last one I use here -- an automatically assembled interceptor COM. opensymphony. xwork. spring. interceptor. the key code of actionautowiringinterceptor is as follows:

Applicationcontext = (applicationcontext) actioncontext. getcontext (). getapplication (). Get (
Webapplicationcontext. root_web_application_context_attribute );
Factory = new springobjectfactory ();
Factory. setapplicationcontext (getapplicationcontext ());
Action bean = invocation. getaction ();
Factory. autowirebean (bean );

Actioncontext. getcontext (). Put (application_context, context );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.