整合Mybatis

一,回忆mybatis

1.导包

2.编写实体类

3.编写核心配置文件

4.编写接口

5.编写Mapper.xml

6.测试

 

二 ,整合Mybatis

1.导包

  junit

  mybatis

  mysql

  spring相关包

  aop织入

  mybatis-spring

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>

<!--Spring操作数据库的话,还需要一个spring-jdbc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
</dependencies>

2.编写配置文件

相比Mybatis多一个接口实现类

 

3.测试

 这里的xml我整合了两个所以用的applicationContext.xml

方式二

 

 

posted on 2022-04-25 15:54  键盘敲烂的朱  阅读(33)  评论(0编辑  收藏  举报