yml文件配置mybatis
时间: 2023-05-29 16:05:16 浏览: 380
在yml文件中配置MyBatis需要以下步骤:
1. 添加MyBatis依赖
```yaml
dependencies:
# ...
# 添加MyBatis依赖
- org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3
```
2. 配置数据源
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
```
3. 配置MyBatis
```yaml
mybatis:
mapper-locations: classpath:mapper/*.xml
```
- mapper-locations:指定mapper文件的位置,可以使用通配符。
4. 配置扫描包
```yaml
mybatis:
type-aliases-package: com.example.entity
```
- type-aliases-package:指定实体类所在的包。
完整的yml文件示例:
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.entity
```
阅读全文
相关推荐















