一、导入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
二、配置application.yml/properties
1、配置数据源(DruidDataSource连接池)
application.yml方式
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/rbac?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
2、配置Mybatis
mybatis:
typeAliasesPackage: com.woniuxy.springboot.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
lazy-loading-enabled: true
aggressive-lazy-loading: false
mapper-locations: classpath:mapper/*.xml
三、主启动类添加扫描配置
@SpringBootApplication
@MapperScan("com.woniuxy.springboot.mapper")
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
@MapperScan("com.woniuxy.springboot.mapper")自动扫描该包下面所有的mapper接口,不需要再添加@Mapper配置