SSM框架整合

1.创建数据库表

数据库环境搭建

CREATE DATABASE `ssmbuild`;

USE `ssmbuild`

DROP TABLE IF EXISTS `books`;

CREATE TABLE `books`(
bookID INT(10) NOT NULL AUTO_INCREMENT COMMENT '书id',
bookName VARCHAR(100) NOT NULL ,
bookCounts INT(11) NOT NULL ,
detail VARCHAR(200) NOT NULL ,
KEY bookID (bookID)
)ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO books (bookID,bookName,bookCounts,detail)VALUES
(1,'java',1,'从入门到放弃'),
(2,'MySQL',10,'从删库到跑路'),
(3,'Linux',5,'从进门到坐牢');

2.搭建IDEA环境

创建普通Maven项目,添加web框架4.0

2.1添加pom.xml依赖



    
   
        
            junit
            junit
            4.12
        
        
        
            mysql
            mysql-connector-java
            5.1.47
        
        
        
            com.mchange
            c3p0
            0.9.5.2
        
        
        
            javax.servlet
            servlet-api
            2.5
        
        
            javax.servlet.jsp
            jsp-api
            2.2
        
        
            javax.servlet
            jstl
            1.2
        


        
            org.mybatis
            mybatis
            3.5.2
        
        
            org.mybatis
            mybatis-spring
            2.0.2
        


        
            org.springframework
            spring-webmvc
            5.1.9.RELEASE
        
        
            org.springframework
            spring-jdbc
            5.1.9.RELEASE
        


    


2.2静态资源导出问题


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

3.IDEA连接数据库

SSM框架整合_第1张图片

 SSM框架整合_第2张图片

 4.构建基本结构和配置框架

SSM框架整合_第3张图片

4.1 mybatis-config.xml





4.2 applicationContext.xml



 
 

5.mybatis层的编写

database.properties文件的编写

jdbc.driver=com.mysql.jdbc.Driver
#如果使用的是MySQL8.0+,增加一个时区的配置;&serverTimezone=Asia/Shanghai
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=2001

Dao层 

SSM框架整合_第4张图片





     

         
     

    
        
    

 





    
        INSERT INTO books (bookName,bookCounts,detail) VALUES (#{bookName},#{bookCounts},#{detail});
    

    
        delete
        from books
        where bookID=#{bookID};
    

    
        UPDATE
            `ssmbuild`.`books`
        SET
            `bookName` =#{bookName},
            `bookCounts` = #{bookCounts},
            `detail` = #{detail}
        WHERE `bookID` = #{bookID};
    

    

    

你可能感兴趣的:(SpringMVC,spring,java)