The previous blog talked about the integration and merging of Struts2 + Spring, mainly using an intermediate jar package. This blog is added with the Ibatis persistent layer framework, and the three frameworks are merged. Struts2 and Spring are the same as those in the front. They mainly explain the merger between Spring and Ibatis. Here they also involve Spring's AOP programming ideas and the use of declarative transactions.
I. Let's take a look at the division of labor:
Struts2: Responsible for process control, mainly for the process from the JSP page to the action class.
Spring: Creates classes and objects, including action, service, dao, data connection object, sqlMapClient, and transactionManager, the core object of the Ibatis framework.
Ibatis: encapsulates JDBC and simplifies data access procedures.
2. Environment Construction:
1. The jar package to be tested:
Commons-fileupload-1.2.1.jar (Struts2: File Upload)
Commons-io-1.3.2.jar (Struts2: File Upload)
Freemarker-2.3.15.jar (Struts2: View presentation technology)
Ognl-2.7.3.jar (Struts2: Object graphics Navigation language for Data Operations)
Struts2-core-2.1.8.1.jar (Struts2: Core jar package)
Xwork-core-2.1.6.jar (Struts2: Core jar package of webwork Framework)
Commons-logging.jar (Spring: log output operations to achieve the conversion of log output)
Junit-3.8.2.jar (not required: unit test jar package)
Log4j-1.2.15.jar (not required: log output jar package)
Spring. jar (Spring: Core jar package)
Struts2-spring-plugin-2.1.8.1.jar (combined jar packages for Struts2 and Spring)
C3p0-0.9.1.2.jar (jar package for Data Source Operations)
Ibatis-2.3.4.726.jar (Ibatis: Core jar package)
Ojdbc14.jar (oracle database connection jar package)
Aspectjrt. jar (Spring: jar packages that support the AOP function)
Aspectjweaver. jar (Spring: jar packages that support the AOP function)
Cglib-nodep-2.1_3.jar (Spring: Implement inheritance-based Dynamic proxy)
2. The copied configuration file:
Struts2: struts. xml
Spring: applicationContext. xml
Ibatis: SqlMapConfig. xml and SqlMap. xml
Log output attribute file: log4j. properties
Configure database connection information: db. properties
3. Write configuration files:
1. In struts. xml, it is mainly used to configure the action class,
/userlist.jsp
/error.jsp
2. applicationContext. xml:
Classpath: db. properties
Classpath: SqlMapConfig. xml
3. SqlMapConfig. xml
4. User. xml (SqlMap. xml)
insert into t_user(usercode,userpswd,username,orgtype,regdate) values(#usercode#,#userpswd#,#username#,#orgtype#,#regdate#)
5. properties file db. properties:
url=jdbc:oracle:thin:@127.0.0.1:1521:ljhdriverClass=oracle.jdbc.driver.OracleDriverusername=scottpassword=ti
4. jsp and other layer-3 are not provided here. However, it is reminded that the Exception must be caught by the framework in the service to make the transaction take effect. The Dao layer can directly use sqlMapClient to call the addition, deletion, modification, and query methods.
In this way, the merging of the three frameworks is completed. In practice, we can add relevant classes based on the business and add relevant configuration files. In short, multiple applications.