SSM整合

1、创建Model

2、导入依赖


  4.0.0
  com.xiaoan
  ssm
  war
  1.0-SNAPSHOT
  ssm Maven Webapp
  http://maven.apache.org
  
    5.3.1
  
  
    
      org.springframework
      spring-context
      ${spring.version}
    
    
      org.springframework
      spring-beans
      ${spring.version}
    
    
    
      org.springframework
      spring-web
      ${spring.version}
    
    
      org.springframework
      spring-webmvc
      ${spring.version}
    
    
      org.springframework
      spring-jdbc
      ${spring.version}
    
    
      org.springframework
      spring-aspects
      ${spring.version}
    
    
      org.springframework
      spring-test
      ${spring.version}
    
    
    
      org.mybatis
      mybatis
      3.5.7
    
    
    
      org.mybatis
      mybatis-spring
      2.0.6
    
    
    
      com.alibaba
      druid
      1.0.9
    
    
    
      junit
      junit
      4.12
      test
    
    
    
      mysql
      mysql-connector-java
      8.0.16
    
    
    
      log4j
      log4j
      1.2.17
    
    
    
      com.github.pagehelper
      pagehelper
      5.2.0
    
    
    
      ch.qos.logback
      logback-classic
      1.2.3
    
    
    
      javax.servlet
      javax.servlet-api
      3.1.0
      provided
    
    
    
      com.fasterxml.jackson.core
      jackson-databind
      2.12.1
    
    
    
      commons-fileupload
      commons-fileupload
      1.3.1
    
    
    
      org.thymeleaf
      thymeleaf-spring5
      3.0.12.RELEASE
    
  
  
    ssm
  

3、创建表

CREATE TABLE `t_emp` (
    `emp_id` int(11) NOT NULL AUTO_INCREMENT,
    `emp_name` varchar(20) DEFAULT NULL,
    `age` int(11) DEFAULT NULL,
    `sex` char(1) DEFAULT NULL,
    `email` varchar(50) DEFAULT NULL,
    PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

4、配置web.xml




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


  
  
    HiddenHttpMethodFilter
    org.springframework.web.filter.HiddenHttpMethodFilter
  
  
    HiddenHttpMethodFilter
    /*
  


  
  
    DispatcherServlet
    org.springframework.web.servlet.DispatcherServlet
    
    
      contextConfigLocation
      classpath:SpringMVC.xml
    
    1
  
  
    DispatcherServlet
    /
  


  
  
    contextConfigLocation
    classpath:Spring.xml
  
  
  
  
  
    org.springframework.web.context.ContextLoaderListener
  

5、创建SpringMVC的配置文件并配置






    
    

    
    
        
        
        
            
                
                    
                        
                        
                        
                        
                        
                        
                    
                
            
        
    

    
    

    
    

    
    


    
    

    
    

6、创建Spring的配置文件并配置




    
    
        
    


    
    

    
    
        
        
        
        
    

    
    
        
        
        
        
        
        
        


    
    
    
        
    

7、搭建MyBatis环境

7.1 创建属性文件jdbc.properties

jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC
jdbc.driver=com.mysql.cj.jdbc.Driver

7.2 创建Mybatis核心配置文件mybatis-config.xml




    

    
        
        
        
        
        
        
    


7.3 创建Mapper接口和映射文件

mapper接口

public interface EmployeeMapper {
List getEmployeeList();
}
映射文件




    

7.4 创建日志文件log4j.xml




    
        
        
            
        
    
    
        
    
    
        
    
    
        
        
    

你可能感兴趣的:(ssm)