千峰商城-springboot项目搭建-02-整合mybatis

 1.在mapper子工程的pom文件新增mybatis所需的依赖。
    <dependencies>
        <dependency>
            <groupId>com.qfedu</groupId>
            <artifactId>beans</artifactId>
            <version>2.0.1</version>
        </dependency>

<!--        mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>

<!--        springboot-starter-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.6.6</version>
        </dependency>

<!--        mybatis starter-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>
    </dependencies>

 

 

 

2.在mapper子工程的resources目录创建application.yml。

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/db_2010_mybatis?characterEncoding=utf-8
    username: root
    password: 123456

mybatis:
  mapper-locations: classpath:mappers/*Mapper.xml
  type-aliases-package: com.qfedu.fmmall.entity
  

 

 

3.在api子工程的启动类通过 @MapperScan 声明 dao包的路径。

package com.qfedu.api;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.qfedu.fmmall.dao")
public class ApiApplication {

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

}
 
posted @ 2022-04-28 20:37  临易  阅读(40)  评论(0编辑  收藏  举报