SPRINGMVC mode
First build the spring frame, then the struts2 frame, and finally the Hibernate framework, please refer to the building process (https://jingyan.baidu.com/article/f25ef2544dfc81482d1b8279.html).
The configuration file in the SSH Framework applicationcontext.xml the Spring framework and the Hibernate framework data, the STRUTS2 framework implements the action class data mapping, and finally the three frameworks are integrated through Web. Xml.
The following packages are generally created under the project file:
1:dao creates the data Access DAO interface, Daoimpl implements the specific DAO interface through inheritance Hibernatedaosupport, obtains the database information through the internal anonymous class, or passes the hibernatetemplate (). Get () method to obtain the database data for the current class. At this point, you need to configure the <bean> in the Applicationcontext.xml configuration file to implement DAO and session mapping to achieve data interface and database data access.
Eg: (Inject sessionfactory into the DAO Class)
<bean id="Foodsdao"class="Com.delicous.dao.impl.FoodsDaoImpl">
<property name="sessionfactory" ref="sessionfactory"/>
</bean>
Eg:gethibernatetemplate (). Get (object name. class, attribute PK value) Gets the primary key information.
Hibernatetemplate (). Executefind () Return collection
Hibernatetemplate (). Execute () Returns an object property value
"Note": generally implemented in the Daoimpl method in the main function of the data test to see whether the function is created. Success.
2: Next, create the Biz interface and the class that Bizimpl implements the interface in turn. The methods in the Biz interface are the same as in DAO, whereas in Bizimpl the business layer data access is implemented only by referencing the DAO object. In this case, you need to configure the Applicationcontext.xml <bean> to implement DAO and biz mapping.
Eg: (Inject Foodsdao into biz, at which time the set and get methods in Foodsdao can be called in biz)
<bean id="foodsbiz" class="Com.delicous.biz.impl.FoodsBizImpl">
<property name="Foodsdao" ref="Foodsdao"></property>
</bean>
"Note": generally implemented in the Bizimpl method in the main function for data testing, to see if the function is created.
3: Next create the action class, by referencing the Biz object, implement the string type method to complete the corresponding data invocation function and then configure the configuration file. Now inject biz into action in Applicationcontext.xml and then configure <action> in the Struts.xml configuration file to pass data from the database to the JSP page.
Eg: (injects foodsbiz into the action, in which the set and get methods in Foodsbiz can be called)
<bean id="foodsaction" class="Com.delicous.action.FoodsAction">
<property name="foodsbiz" ref="foodsbiz"></property>
</bean>
Eg: (The display of database to JSP data via action in struts2)
<action name="foodslist" class="foodsaction " method="list">
<result name="Success">/foodslist.jsp</result>
</action>
Finally, the corresponding data of the table in the database can be obtained directly through the EL expression in the JSP page.
Of course, this is only a way to implement the SSH framework, only for novice reference.
The construction of SPRINGMVC