第一步,在pom.xml文件中引入依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
第二步,在application.yml中配置 数据库连接信息 和 mybatis配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/test
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
#配置mybatis
mybatis:
type-aliases-package: zchao.com.springboot.generator.model
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#开启MyBatis的二级缓存
cache-enabled: true
#开启懒加载
lazy-loading-enabled: true
#false 为按需加载
aggressive-lazy-loading: false
mapper-locations: classpath:mapper/*.xml