SpringBoot项目配置文件、yml配置文件
一. 配置文件格式
1. SpringBoot项目提供了多种属性配置方式(properties、yaml、yml)。
二. yml配置文件
1. 格式:
(1) 数值前边必须有空格,作为分隔符。
(2) 使用缩进表示层级关系,缩进时,不允许使用Tab键,只能使用空格(idea中会自动将Tab转换为空格)
(3) 缩进的空格数目不重要,只要相同层级的元素左侧对其即可。
(4) # 表示注释,从这个字符一直到行尾。都会被解析器忽略。
2. 定义对象/Map集合:
Emp:name: 卡莎age: 18
3. 定义数组/List/Set集合
names:- 卡莎- 泰坦- 张飞
4. 注意:在yml格式的配置文件中,如果配置项的值是以 0 开头的,值需要使用 ' '单引号引起来,因为以0开头在yml中表示8进制的数据
5. 将properties文件换为yml文件
spring:application:name: Java-MyBatis# 配置Mybatis数据库连接信息datasource:type: com.alibaba.druid.pool.DruidDataSourceurl: jdbc:mysql://localhost:3306/db01driver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root# mybatis的日志输出 (输出到控制台)
mybatis:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# 配置mybatis的mapper文件位置mapper-locations: classpath:mapper/*.xml