The SSM framework is one of the most popular project architectures, using the three frameworks of spring, SPRINGMVC, and MyBatis to build the project's main architecture. The key to the SSM framework consolidation is the integration of spring with MyBatis, which describes the three frameworks in turn and how to integrate them, incidentally, the SVN and MAVEN tools.
First, Spring, SPRINGMVC, MyBatis Basic concepts
1, Spring
Spring is a middle-tier framework for object management, object Association, and decoupling, created to address the complexities of enterprise application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJB. However, the purpose of Spring is not limited to server-side development. In terms of simplicity, testability, and loose coupling, any Java application can benefit from Spring. In short, Spring is a lightweight control reversal (IoC) and aspect-oriented (AOP) container framework.
2, Springmvc
Spring MVC is a follow-on product of Springframework and has been merged into Spring Web flow. The spring Framework provides a full-featured MVC module for building Web applications, so you can use the Spring MVC architecture directly when you are doing web development. The Spring MVC Framework is a request-driven web framework that is designed using a front-end controller pattern and distributed to the appropriate page controller for processing based on the request mapping rules.
3, MyBatis
MyBatis is an open source project for Apache IBatis, the project was migrated from Apache Software Foundation to Google code in 2010 and renamed MyBatis. MyBatis is a Java-based persistence layer framework. The persistence layer framework provided by IBatis includes SQL Maps and Data Access Objects (DAO). MyBatis eliminates the manual setting of almost all JDBC code and parameters and the retrieval of result sets. MyBatis is a data persistence layer (ORM) framework that establishes a mapping relationship between entity classes and SQL statements, and is a semi-automatic ORM implementation
Second, the characteristics of MyBatis
Based on SQL syntax, SQL statements are encapsulated in a configuration file to facilitate unified management and maintenance.
Low degree of automation, manual mapping of SQL, high degree of flexibility.
Third, MyBatis Development steps
1, add MyBatis jar package main jar package +lib under JAR package + database connection Jar Package
2, write MyBatis configuration file Mybatis-config.xml
typealiases Java category name;
Typehandlers type processor;
Settings behavior: lazyloadingenabled lazy load cacheenabled cache
Environment environment variables;
Mappers mapping;
TransactionManager transaction manager: <transactionmanagertype= "[jdbc| MANAGED] "/>
DataSource data Source: <datasourcetype= "[unpooled| pooled| JNDI] "/>
3. Write entity classes and SQL mapping files such as: Usermapper.xml
4. Create DAO interface and interface implementation class
5, write test class for testing
Four, MyBatis the operation steps of the persistence
1. Load MyBatis configuration file
Reader Reader=resources.getresourceasreader ("Mybatis-config.xml");
2. Create the session Factory builder and construct sessionfactory
Sqlsessionfactorybuilder builder = new Sqlsessionfactorybuilder ();
Sqlsessionfactory sessionfactory = builder.build (reader);
3, get the session session=sessionfactory.opensession ();
4, Business Operation Session.commit ();
5, close session session.close ();
Top elements of the SQL map file
SQL mapping file: Each entity class corresponds to a SQL mapping file, including some crud SQL statements
Cache-Configure caching for a given namespace cache-ref– from other namespaces referencing cache configuration
Resultmap used to describe the corresponding relationship between the database result set and the object
ParameterType will pass in the fully qualified name or alias of the argument class for this statement.
Resulttype the fully qualified name or alias of the class of the desired type returned from this statement
UseCache set it to true will cause the result of this statement to be cached
Flushcache sets it to true, causing the cache to be cleared
Fetchsize This is the number of result rows that imply that the driver returns each batch.
Vi. Principle of SPRINGMVC frame
The following steps are implemented:
1, the first user to send the request ———— > front-end controller, the front-end controller based on the request information (such as URL) to decide which page controller to process and entrust the request to it, that is, the control of the previous controller logic part of the 1, 2 steps in Figure 2-1;
2, the page controller receives the request, carries on the function processing, first needs to collect and bind the request parameter to an object, this object is called the Command object in the Spring Web MVC, validates, and then delegates the command object to the business object for processing ; Returns a modelandview (model data and Logical view name) after processing, 3, 4, 5 steps in Figure 2-1;
3, the front-end controller to reclaim control, and then according to the return of the logical view name, select the appropriate view for rendering, and the model data passed to the view rendering, in Figure 2-1 steps 6, 7;
4. The front-end controller will regain control again, return the response to the user, step 8 in Figure 2-1, and end this whole.
Development Steps of Spring MVC
1. Add Spring Springmvc jar Pack
2, configure the front-end controller Web.xml
Load-on-startup: Initializes the servlet when the container is started;
3. Configure Context:component-scan, viewresolver in the Spring MVC configuration file
4. Add model data and set logical view name in Page Controller (Controller Class)
5, modify the View page –jsp page
Eight, spring and mybatis consolidation steps
1, build the project, add Spring and mybatis of the relevant jar pack
2, establish the development directory structure, create entity classes
3. Create Data Access layer: DAO interface and interface implementation class
4. Configure SQL mapping statement files and Web.xml filter files
5. Configure the Spring application configuration file, Spring Association MyBatis
6. Create Business Logic Layer: Service Interface and interface implementation class
7. Create control layer: Add model data and set logical view name
Nine, Maven tools
MAVEN is a Cross-platform project management tool. It mainly serves the project construction based on Java platform, relies on management and project information management.
Dependency management refers to using MAVEN to manage the jar packages used in a project, and the Maven tool automatically downloads the jar packages needed for the project and manages the dependencies between the jar packages.
Benefits of Maven:
MAVEN uses conventions to explicitly specify the Java source code and which directory to put the compiled Java code in.
Each action of Maven has a lifecycle, such as a build process to perform MVN install
Just define a pom.xml and then put the source in the default directory, and Maven will help us with everything else.
Using MAVEN, you can build a highly automated project, relying on management (which is the greatest benefit of using MAVEN), warehouse management.
X. SVN tools
SVN is a subversion abbreviation, is an open source version control system, compared to RCS, CVS, it uses a branch management system, its design goal is to replace CVS. Many version control services on the Internet have migrated from CVs to subversion. It's easy to say. SVN is used for multiple individuals to jointly develop the same project and share resources.
SVN use steps:
1. Build SVN server
2. Install SVN client
3, use the SVN tool checkout, add, delete, update function