一. 配置文件格式
- SpringBoot项目提供了多种属性配置方式(properties、yaml、yml)。


二. yml配置文件
- 格式:
(1) 数值前边必须有空格,作为分隔符。
(2) 使用缩进表示层级关系,缩进时,不允许使用Tab键,只能使用空格(idea中会自动将Tab转换为空格)
(3) 缩进的空格数目不重要,只要相同层级的元素左侧对其即可。
(4) # 表示注释,从这个字符一直到行尾。都会被解析器忽略。
- 定义对象/Map集合:
java
Emp:
name: 卡莎
age: 18
- 定义数组/List/Set集合
java
names:
- 卡莎
- 泰坦
- 张飞

-
注意:在yml格式的配置文件中,如果配置项的值是以 0 开头的,值需要使用 ' '单引号引起来,因为以0开头在yml中表示8进制的数据
-
将properties文件换为yml文件

java
spring:
application:
name: Java-MyBatis
# 配置Mybatis数据库连接信息
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db01
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
# mybatis的日志输出 (输出到控制台)
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 配置mybatis的mapper文件位置
mapper-locations: classpath:mapper/*.xml