其他博客里写了
pom.xml中添加依赖
<!--MySQL驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--MyBatis整合SpringBoot框架的起步依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
application.properties文件中添加
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/zq_db_test
spring.datasource.username=root
spring.datasource.password=root123
model、mapper接口、mapper.xml
其他博客里写了
每个Mapper接口的接口明上添加@Mapper注解
不需要每个Mapper接口的接口明上添加@Mapper注解
只要 在启动类的类名上添加
@MapperScan(basePackages = "com.zq.springboot001.mapper")
需要在pom.xml中添加
<!-- 手动指定文件夹为resources, 否则,mapper.xml不会被编译到target中的对应目录中 -->
<!-- build标签中,和plugins标签同级 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
不需要 5.1中在pom.xml配置的resources标签
只要 在application.properties文件中添加
#指定MyBatis映射文件的路径
mybatis.mapper-locations=classpath:mappers*.xml
解决办法:
在Mapper接口上添加@Repository注解即可
原文:https://www.cnblogs.com/yezi-zq/p/14731246.html