/**
*随着学习的东西越来越多 很多东西都会遗忘 ;
*就想着写写文章记录一下 以便后期回顾
*软件:ideal
*框架:Spring Boot、Mybatis
*/
一、我们使用SpringBoot整合mybatis会发现直接将xml放在和mapper在同一目录时,发现根本不好使,找不到。
这时候才想起SpringBoot的 理念就是零配置,但是我们要用啊。这时候就需要进行要写简单的配置了。
二、如何配置呢?
大致分为三步
1.导入相对应的pom文件
<!--导入相关的依赖 mybatis和mysql的连接必不可少-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
2.在application.yml或者application.properties中配置 xml的位置
<!--这是在application.yml中-->
mybatis:
mapper-locations: classpath:mapper/*.xml
<!--这是在application.properties中-->
mybatis.mapper-locations: classpath:mapper/*.xml
3.在resources中新建mapper目录,里面放入xml文件(这里取什么名,配置文件中就叫什么名,要对应,否则找不到)
4.其它的xml中配置的和以前用ssm ssh框架时的一样的,不再简述
-------------------------------------------结束,若有不对,欢迎指点。-----------------------------------------------