spring整合mybatis


添加依赖包

mysql依赖包 + 连接池dbcp + mybatis依赖包 +
spring-jdbc依赖包 + mybatis-spring依赖包



  mysql
  mysql-connector-java
  5.1.44



  commons-dbcp
  commons-dbcp
  1.4



  org.mybatis
  mybatis
  3.4.5



  org.mybatis
  mybatis-spring
  1.3.0



  org.springframework
  spring-jdbc
  3.2.8.RELEASE

创建数据库配置文件db.properties

# data-source
url=jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
driver=com.mysql.jdbc.Driver
username=root
password=root
initialSize=2
maxActive=10

spring文件中配置





    
    
    
    
    
    



    



    
    

创建mapper文件

  



    
      insert into user (userName, password, age, phone, email) values
      (#{userName}, #{password}, #{age}, #{phone}, #{email})
    
    
      delete from user where id=#{id}
    

    
      update user set userName=#{userName}, password=#{password},
      age=#{age}, phone=#{phone}, email=#{email}
      where id=#{id}
    

    

你可能感兴趣的:(spring整合mybatis)