springMvc-09 SSM框架整合


框架整合的方便之处

1)单独使用myBatis的时候,要操作数据库,每次都需要通过SqlSessionFactory和SqlSession方式获取Mapper对象

2)在Spring和Mytis整合之后,无需再通过SqlSessionFactory和SqlSession方式获取Mapper对象,所有Mapper和Dao对象都交给了Spring框架管理,获取Bean的时候,通过ApplicationContext对象获取即可。

3)SSM框架整合是把三大框架整合在一起使用,Web.xml导入Spring配置和SpringMvc配置,在Web容器启动的时候,启动Spring框架容器,从Model,Dao,Service,Controller都采用注解方式,就可以实现直接在Controller里边使用Service的注入对象,无需再使用ApplicationContext获取Bean对象。

1、pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>

    4.0.0

    org.rui
    02QuickAnnotation
    1.0-SNAPSHOT
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    7
                    7
                
            

            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    true
                
            

        
    

    

        
        
        
        
            org.springframework
            spring-context
            5.3.0
        

        
        
            org.springframework
            spring-aop
            5.3.0
        

        
        
            org.springframework
            spring-beans
            5.3.0
        

        
        
            org.springframework
            spring-core
            5.3.0
        

        
        
            org.springframework
            spring-aspects
            5.3.0
        

        
        
            org.springframework
            spring-expression
            5.3.0
        

        
        
            org.springframework
            spring-instrument
            5.3.0
        

        
        
            org.springframework
            spring-orm
            5.3.0
        

        
        
            org.springframework
            spring-web
            5.3.0
        

        
        
            org.springframework
            spring-webmvc
            5.3.0
        

        
        
            org.springframework.boot
            spring-boot
            2.6.0
        

        
        
            javax.servlet
            jstl
            1.2
        

        
        
        
            org.springframework
            spring-jdbc
            5.3.0
        

        
        
            org.springframework
            spring-tx
            5.3.0
        

        
        
        
            org.springframework
            spring-test
            5.3.0
            test
        

        
        
        
            com.alibaba
            druid
            1.2.0
        

        
        
        
            mysql
            mysql-connector-java
            8.0.11
        

        
        
        
        
            org.mybatis
            mybatis
            3.5.6
        

        
        
        
            org.mybatis
            mybatis-spring
            2.0.6
        

        
        
        
            junit
            junit
            4.13
            test
        

        
        
        
            log4j
            log4j
            1.2.17
        

        
        
        
            com.fasterxml.jackson.core
            jackson-core
            2.12.2
        

        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.12.2
        

        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.12.2
        

        
            org.jetbrains
            annotations-java5
            RELEASE
            compile
        

    

2、web.xml配置

<?xml version="1.0" encoding="UTF-8"?>


    
    
        contextConfigLocation
        classpath:spring.xml
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:springmvc.xml
        
        
        1
    

    
    
        springmvc
        /
    

    
    
        CharacterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
        
            encoding
            UTF-8
        
        
        
            forceRequestEncoding
            true
        
        
        
            forceResponseEncoding
            true
        
    
    
        CharacterEncodingFilter
        /*
    

    
    
        index
    

3、spring.xml配置

<?xml version="1.0" encoding="UTF-8"?>



    
    

    
    
        
        
        
        
        
        
        
        
        
        
        
        
    

    
    
        
    

    
    

    
    
        
        
    

    
    
    
        
        
    

    
    

4、springmvc.xml配置

<?xml version="1.0" encoding="UTF-8"?>


    
    

    
    

    
    

    
    
        
        
    

5、mybatis.xml配置

<?xml version="1.0" encoding="UTF-8" ?>




    
    
        
        
    

    
    
        
        
        
        
        
        
        
        
    

    
    
        
        
    

    
    
    
    
        
        
        
        
        
    



相关