SSM 整合配置实例

pom 文件




    4.0.0

    com.shsxt
    ssm
    1.0-SNAPSHOT
    war

    ssm Maven Webapp

    
        UTF-8
        1.8
        1.8
    

    
        
            junit
            junit
            4.12
            test
        
        
        
            org.springframework
            spring-context
            4.3.2.RELEASE
        

        
        
            org.springframework
            spring-test
            4.3.2.RELEASE
        

        
        
            org.springframework
            spring-jdbc
            4.3.2.RELEASE
        

        
        
            org.springframework
            spring-tx
            4.3.2.RELEASE
        

        
        
            org.aspectj
            aspectjweaver
            1.8.9
        

        
        
            c3p0
            c3p0
            0.9.1.2
        

        
        
            org.mybatis
            mybatis
            3.4.1
        

        
        
            org.mybatis
            mybatis-spring
            1.3.0
        
        
        
            mysql
            mysql-connector-java
            5.1.39
        

        
        
            org.slf4j
            slf4j-log4j12
            1.7.2
        
        
            org.slf4j
            slf4j-api
            1.7.2
        

        
        
            com.github.pagehelper
            pagehelper
            4.1.0
        

        
        
            org.springframework
            spring-web
            4.3.2.RELEASE
        

        
        
            org.springframework
            spring-webmvc
            4.3.2.RELEASE
        

        
        
            javax.servlet
            javax.servlet-api
            3.0.1
        

        
        
            com.fasterxml.jackson.core
            jackson-core
            2.7.0
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.7.0
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.7.0
        

        
        
            commons-fileupload
            commons-fileupload
            1.3.2
        

    
    
        ssm
        
        
            
                src/main/resources
            
            
                src/main/java
                
                    **/*.xml
                    **/*.properties
                    **/*.tld
                
                false
            
        

        
        
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2
                
                    src/main/resources/generatorConfig.xml
                    true
                    true
                
                
                    
                        org.mybatis.generator
                        mybatis-generator-core
                        1.3.2
                    
                
            

            
            
        

    

Spring 上下文环境

spring.xml:




    
    
        
    

    
    

    
    

    
    
        
        
        
        
    

    
    
        
    

    
    
        
            
            
            
            
            
            
            
            
            
            
        
    

    
    
        
        
    

    
    
        
            
        
    

    
    
               
        
    

SQLSession 的 bean 指定了 mybatis主配置文件, 配置如下:

mybatis.xml




    
    
        
    

    
    
        
    

    
    
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    


下面是 webmvc 相关配置

web.xml



    
    
        contextConfigLocation
        classpath:spring.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        char encoding filter
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    
    
        encodingFilter
        /*
    

    
    
        springMvc
        org.springframework.web.servlet.DispatcherServlet
        
            
            contextConfigLocation
            classpath:servlet-context.xml
        
        1
    
    
        springMvc
        /
    

上面的 web.xml 不仅关联了 spring.xml, 还为 DispatcherServlet 指定了上下文环境, 我们需要 webmvc 环境的配置文件

servlet-context.xml





    
    

    
    

    
    
        
        
        
        
        
    

    
    
    
        
            
                
            
        
    

    
    
        
            104857600
        
        
            4096
        
    


最后是 mybatis-generator 插件的配置

generatorConfig.xml




    
    
    
        
            
            
        
        
        
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
            
        

        

db.properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&useSSL=true
jdbc.username=root
jdbc.password=111111

log4j.properties:

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

你可能感兴趣的:(ssm原理)