SpringBoot系列教程(三)集成MyBatis、Druid

1.添加MyBatis和Druid对应依赖包

        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.0
        

        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.10
        

Druid详细参数配置介绍:druid-spring-boot-starter

2、创建配置文件(application.yml)

配置Druid

spring:
  datasource:
    druid:
      url: jdbc:mysql://ip:port/dbName?useSSL=false
      username: username
      password: password
      driver-class-name: com.mysql.cj.jdbc.Driver

配置Mybatis

mybatis:
  mapper-locations: classpath:mybatis/mapper/*.xml
  configuration:
    map-underscore-to-camel-case: true
    use-generated-keys: true

3、主启动类上新增Mappe接口扫描

@SpringBootApplication
@MapperScan("com.lemonzuo.mapper")
public class LearnApplication {

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

}

4、Mybatis接口编写、xml文件编写与传统SSM方式一致。

你可能感兴趣的:(SpringBoot)