Introduction to SSM framework and integration tutorial
1.Spring
Spring framework is the most widely used framework in Java. Its success comes from the concept rather than the technology itself. Its concepts include IOC (control inversion) and a (aspect oriented programming). Spring framework is a lightweight Java EE framework. The so-called lightweight means that it can run without relying on the container. Simply put, spring is a lightweight inversion of control (IOC) and aspect oriented (AOP) container framework.
2.Spring MVC
It acts on the web layer, which is equivalent to the controller. Like the action in struts, it is used to process user requests. At the same time, compared with struts 2, it is more fine-grained. It is based on the method level, while struts is based on the class level. Spring MVC separates the roles of controller, model object, dispatcher and handler object, which makes them easier to customize.
Comparison between struts 2 and spring MVC:
3.MyBatis
Mybatis was originally an open source project ibatis of Apache. In 2010, the project was migrated from Apache Software Foundation to Google Code and renamed mybatis. Mybatis is an excellent persistence layer framework, which supports customized SQL, stored procedures and advanced mapping. Mybatis avoids almost all JDBC code and manually setting parameters and getting result sets. Mybatis can use simple XML or annotations to configure and map native information, and map interfaces and Java POJOs (plain old Java objects) to records in the database.
Comparison between hibernate and mybatis:
4. SSM framework integration
This project will take shopping as the background, mainly including commodity information, inventory [because I want to learn about transaction processing] and order information. The following will explain step by step from the aspects of database creation, project structure description, configuration file, business code, etc.
4.1 database creation
1. Commodity list
Initialize table data
2. Order form
OK, so far, the table structure and initialization data are built. Let's talk about the mavan based project structure.
Because the project uses Maven to manage jar packages, let's post it first, POM Configuration POM. XML In order to avoid the learning partners' advocating of taking things [that is, removing things like xmlns], only the dependencies of the jar package that the project depends on are put here; this case will be based on the principle of "use when needed", so as to avoid all kinds of messy dependencies seen on the Internet, resulting in waste of resources and interference in reading. JUnit JUnit 4.11
4.3 configuration file
jdbc. properties
logback. xml
Console output is directly used here. If it is a production environment, it can be configured according to specific requirements.
spring-service
In the actual development process, transactions are generally operated in the service layer. So use a separate spring service XML for transaction related configuration
spring-web. xml
Configure spring MVC; It should be noted that generally, we will configure json2map parsing in the actual development process. If it is not used here, it will not be posted. Readers can search online by themselves.
web. xml