day63( MYBATIS框架基础1:关于Mybatis框架,创建Mybatis-Spring工程,配置开发环境,基本使用,删除与修改数据)
1.概念:
-
Mybatis的主要作用是快速实现对关系型数据库中的数据进行访问的框架
-
在原生的Java技术中,需要使用JDBC实现对数据库中的数据访问,执行过程繁琐且相对固定,使用框架可以有效的提高开发效率
2.创建Mybatis-Spring工程
-
前提: Mybatis可以不依赖于Spring等框架直接使用的,但是,就需要进行大量的配置,前期配置工作量较大,基于Spring框架目前是业内使用的标准之一,所以,通常会整合Spring与Mybatis,以减少配置
-
在创建工程时,创建普通的Maven工程即可(不需要选择特定的骨架)
1. 在pom.xml中添加几个依赖项
<dependencies>
<!-- Mybatis的依赖项:mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<!-- Mybatis整合Spring的依赖项:mybatis-spring-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!-- Spring的依赖项:spring-context-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.14</version>
</dependency>
<!-- Spring JDBC的依赖项:spring-jdbc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.14</version>
</dependency>
<!-- MySQL连接的依赖项:mysql-connector-java-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<!-- 数据库连接池的依赖项:commons-dbcp2-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>