springBoot整合mybatis开发

1.在pom.xml中引入springBoot与mybatis的整合的jar包,注意别引错:

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>

2.在springBoot的配置文件:application.yml配置mybatis相关的属性:

spring:
  #配置数据源
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/demo1?serverTimezone=UTC
    username: root
    password: root

#配置mybatis相关属性
mybatis:
  #配置mybatis的mapper.xml文件的位置
  mapper-locations: classpath:mapping/*Mapper.xml
  #配置实体类的包别名
  type-aliases-package: com.yzy.springbootdemo.entity

3.在resources目录下创建mapping文件夹存放mapper.xml(与上面配置文件中配置的mapper-locations对应

springBoot整合mybatis开发

 4.在启动类中添加注解@MapperScan("对应的dao接口的路径")

@SpringBootApplication
@MapperScan("com.yzy.springbootdemo.dao")
public class SpringbootdemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootdemoApplication.class, args);
    }

}

详细教程可看:https://blog.csdn.net/iku5200/article/details/82856621?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase