SpringMVC + Spring + Mybatis simple summary

SpringMVC + Spring + Mybatis summary

1、mybatis

mybatis environment to build

The first step in the preparation of sqlMapConfig.xml profile

The second step, the preparation of an entity class interface

The third step is to write the mapping file Mapper.xml

The fourth step is to write the test class, create SqlSession objects

The fifth step, by SqlSession object getMapper get a proxy object

Call the sixth step, achieved through a proxy object method of calling the method

2、Spring

Spring environment to build

Spring core is characterized by IOC and AOP

Profile name

First, create applicationcontext.xml

The second step, read the file in the test class and create applicationContext objects of cx

The third step, by cx.getBean () method to get the object

A fourth step of obtaining an object operated by

AOP follows

The first step in the preparation of class enhancement (Enhanced Object)

The second step in the preparation of the applicationcontext.xml AOP configuration information, such as

<aop:config>
    <aop:aspect id="aspect" class="">
    <aop:before method="before" pointcut="public void *.*..*.*(..)">
    </aop:aspect>
</aop:config>

The fourth step is to write the test class

Spring transaction follows

<! - Transaction Manager Configuration -> 
< bean the above mentioned id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager" > 
    < Property name = "dataSource" ref = "dataSource" /> 
</ bean > <-! notification configuration transaction -> <! - 
    the above mentioned id = "advice" represents id IOC container in the real notification object. 
    transaction-manager = "transactionManager" indicates to which specifies the current transaction manager to be configured 
    if the transaction manager id in the IOC vessel is transactionManager, this configuration can be omitted. -> < TX: the advice ID = "the advice"



= "transactionManager" > 
    < tx: the Attributes > 
        <-! 
            <tx: Method, the starting point of the target object method name 
            name = "*" represents the target object, all methods are the starting point, there must be a transaction. 
            name = "save *" target object to all methods starting to go save the transaction. 
            name = "update *" All the target object to the beginning of the update method to go affairs. 
            name = "delete *" target object to all methods starting to go delete affairs. 
            name = "find *" all methods to find the beginning of the transaction does not go. 
            propagation = "REQUIRED" specified transaction propagation behavior, if you want to configure the transaction REQUIRED, do you configure SUPPORTS, 
            the Read-only = "to true" if read-only, if it is true, that can only do a query operation, there is no transaction. false anything can operate. 
            rollback-for = "" specify an exception, this occurs only roll back abnormal, the remaining abnormal not rolled back. The default configuration does not represent all exceptions are rolled back. 
            no-rollback-for = "
            timeout = "- 1"
            isolation = "" specified transaction isolation level, the default database on the current default transaction isolation level. 
        -> 
        < TX: Method name = "* Save" propagation = "REQUIRED" /> 
        < TX: Method name = "* Update" propagation = "REQUIRED" /> 
        < TX: Method name = "* Delete" propagation = " REQUIRED " /> 
        < TX: Method name =" * Find " Read-only =" to true " /> 
        < TX: Method name =" * " /> 
    </ TX:

3、SpringMVC

The first step in web.xml configuration front controller

A second step of the initialization parameter in the front controller provided ContextConfigLoaction

The third step is the preparation of spring-mvc profile view resolver prepared and open mapping processor and a processor adapter assembly and two annotations.


SSM integration

1 Spring and Mybatis integration,

The first step in applicationcontext.xml add data sources

The second step, in applicationcontext.xml added in the SqlSession ( the SqlSession to be in the container )

The third step, in applicationcontext.xml added in MapperScannerConfig

2 Spring and SpringMVC integration,

Spring and SpringMVC integration simply ensure that web server start Spring container also start to complete integration.

The first step, adding in web.xml ContextLoaderListener project loader listener

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

The second step, reassign Spring configuration file path

<!-- Spring配置文件开始  -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring-config.xml
    </param-value>
</context-param>

 

 

Guess you like

Origin www.cnblogs.com/kitor/p/10991792.html