SpringMVC + Spring + Mybatis整合

  1. 引入相关maven依赖

    
      4.0.0
      com
      mmall
      war
      1.0-SNAPSHOT
      mmall Maven Webapp
      http://maven.apache.org
    
      
        UTF-8
        UTF-8
        UTF-8
    
        4.0.0.RELEASE
        3.4.1
        1.3.0
      
    
      
    
        
          org.apache.tomcat
          tomcat-servlet-api
          7.0.64
        
    
        
          org.springframework
          spring-webmvc
          ${org.springframework.version}
        
    
        
          org.springframework
          spring-oxm
          ${org.springframework.version}
        
    
        
          org.springframework
          spring-jdbc
          ${org.springframework.version}
        
    
        
          org.springframework
          spring-tx
          ${org.springframework.version}
        
    
        
          org.springframework
          spring-test
          ${org.springframework.version}
        
    
        
          org.aspectj
          aspectjweaver
          1.7.3
        
     
        
          org.mybatis
          mybatis-spring
          ${org.mybatis.spring.version}
        
        
          org.mybatis
          mybatis
          ${org.mybatis.version}
        
     
        
          org.aspectj
          aspectjrt
          1.6.11
        
     
        
          org.codehaus.jackson
          jackson-mapper-asl
          1.9.12
        
     
        
          commons-dbcp
          commons-dbcp
          1.4
          
        
     
     
        
          ch.qos.logback
          logback-classic
          1.1.2
          compile
        
        
          ch.qos.logback
          logback-core
          1.1.2
          compile
        
     
        
          mysql
          mysql-connector-java
          5.1.6
        
     
        
          com.google.guava
          guava
          20.0
        
     
     
        
          org.apache.commons
          commons-lang3
          3.5
        
     
     
        
          commons-collections
          commons-collections
          3.2.1
        
     
     
        
          junit
          junit
          4.12
          
        
     
        
          joda-time
          joda-time
          2.3
        
     
     
        
        
          org.hashids
          hashids
          1.0.1
        
     
     
        
        
          commons-net
          commons-net
          3.1
        
     
        
     
        
        
          commons-fileupload
          commons-fileupload
          1.2.2
        
     
        
          commons-io
          commons-io
          2.0.1
        
     
     
     
     
        
     
        
          com.github.pagehelper
          pagehelper
          4.1.0
        
     
        
          com.github.miemiedev
          mybatis-paginator
          1.2.17
        
     
        
          com.github.jsqlparser
          jsqlparser
          0.9.4
        
     
     
        
        
          commons-codec
          commons-codec
          1.10
        
        
          commons-configuration
          commons-configuration
          1.10
        
        
          commons-lang
          commons-lang
          2.6
        
        
          commons-logging
          commons-logging
          1.1.1
        
        
          com.google.zxing
          core
          2.1
        
        
          com.google.code.gson
          gson
          2.3.1
        
        
          org.hamcrest
          hamcrest-core
          1.3
        
     
        
          redis.clients
          jedis
          2.9.0
        
      
     
     
      
        mmall
        
          
            org.mybatis.generator
            mybatis-generator-maven-plugin
            1.3.2
            
              true
              true
            
          
     
          
          
            org.apache.maven.plugins
            maven-compiler-plugin
            
              1.8
              1.8
              UTF-8
              
                ${project.basedir}/src/main/webapp/WEB-INF/lib
              
            
          
        
     
      
    
    
    
    
    
  2. 添加Spring配置文件resources/applicationContext.xml

    
    
    
        
    
        
        
        
    
    
    
    

    引入datasource配置resources/applicationContext-datasource.xml

    
    
    
        
    
        
            
            
            
                
                    classpath:datasource.properties
                
            
            
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
         
        
        
         
        
         
        
        
    
        
        
        
        
        
        
    
    
    
        
        
    
        
        
            
                
                    
                        
                            dialect=mysql
                        
                    
                
            
        
    
    
    
    
        
    
    
    
    
    
    
        
        
    
    
    

    参数记录在resources/datasource.properties

    #db.driverLocation=/Users/imooc/mysql-connector-java-5.1.6-bin.jar
    db.driverLocation=D:/IdeaProjects/mmall_learning/src/main/tools/mysql-connector-java-5.1.6-bin.jar
    db.driverClassName=com.mysql.jdbc.Driver
    
    #db.url=jdbc:mysql://192.1.1.1:3306/mmall?characterEncoding=utf-8
    #db.url=jdbc:mysql://你的数据库IP:你的数据库Port/你的database?characterEncoding=utf-8
    db.url=jdbc:mysql://127.0.0.1:3306/mmall?characterEncoding=utf-8
    db.username=root
    db.password=root
    
    
    db.initialSize = 20
    db.maxActive = 50
    db.maxIdle = 20
    db.minIdle = 10
    db.maxWait = 10
    db.defaultAutoCommit = true
    db.minEvictableIdleTimeMillis = 3600000
    
    
  3. 配置web.xml文件

    
    
    
        Archetype Created Web Application
    
        
            characterEncodingFilter
            org.springframework.web.filter.CharacterEncodingFilter
            
                encoding
                UTF-8
            
            
                forceEncoding
                true
            
        
        
            characterEncodingFilter
            /*
        
    
    
        
            org.springframework.web.context.request.RequestContextListener
        
    
        
            org.springframework.web.context.ContextLoaderListener
        
        
            contextConfigLocation
            
                classpath:applicationContext.xml
            
        
    
        
            dispatcher
            org.springframework.web.servlet.DispatcherServlet
            1
        
    
    
    
        
            dispatcher
            *.do
        
    
    
    
    
    
  4. SpringMVC配置WEB-INF下dispatcher-servlet.xml

    
    
    
        
    
        
            
                
                    
                        
                            text/plain;charset=UTF-8
                            text/html;charset=UTF-8
                        
                    
                
                
                    
                        
                            application/json;charset=UTF-8
                        
                    
                
            
        
    
    
    
        
        
             
            
            
        
    
    
    
    
    
    

  5. 添加日志配置文件lockbak.xml



    
        UTF-8
        
            [%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n
        
        
            DEBUG
        
    

    
        
        D:/Work/Tomcat-IDEA/apache-tomcat-7.0.68/logs/mmall.log
        
            /developer/apache-tomcat-7.0.73/logs/mmall.log.%d{yyyy-MM-dd}.gz
            true
            10
        
        
            [%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n
        
    


    
        
        D:/Work/Tomcat-IDEA/apache-tomcat-7.0.68/logs/error.log
        
            /devsoft/apache-tomcat-7.0.73/logs/error.log.%d{yyyy-MM-dd}.gz
            
            true
            10
        
        
            [%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n
        
        
            ERROR
            ACCEPT
            DENY
        
    

    
        
        
    



    

    

    
        
    

    
        
    
    
        
    

    
        
    


    
        
        
    


你可能感兴趣的:(SpringMVC + Spring + Mybatis整合)