问题描述
所以我刚开始使用 YAML
文件而不是 application.properties
因为它更具可读性.我在 YAML
文件中看到它们以 ---
开头.我google了一下,找到了下面的解释.
So I just started using YAML
file instead of application.properties
as it is more readable. I see in YAML
files they start with ---
. I googled and found the below explanation.
YAML 使用三个破折号(---")将指令与文档分开内容.如果没有,这也用于指示文档的开始存在指令.
另外,我尝试了一个不带 ---
的示例,并了解到并非必须拥有它们.
Also, I tried a sample without ---
and understood that it is not mandatory to have them.
我觉得我对directive
和document
的理解不是很清楚.谁能用一个简单的例子解释一下?
I think I don't have a clear understanding of directive
and document
. Can anyone please explain with a simple example?
推荐答案
正如你已经发现的,三个破折号 ---
用于表示文档的开始,即:
As you already found out, the three dashes ---
are used to signal the start of a document, i.e.:
根据当前规范在指令之后,即
%YAML
或%TAG
行发出文档开始信号.例如:
To signal the document start after directives, i.e.,
%YAML
or%TAG
lines according to the current spec. For example:
%YAML 1.2
%TAG !foo! !foo-types/
---
myKey: myValue
当您同一流中有多个 yaml 文档(例如,一个 yaml 文件)时发出文档开始信号:
To signal the document start when you have multiple yaml documents in the same stream, e.g., a yaml file:
doc 1
---
doc 2
如果 doc 2 有一些前面的指令,那么我们必须使用三个点 ...
来向解析器指示 doc 1 的结尾(以及 doc 2 之前的潜在指令的开始).例如:
If doc 2 has some preceding directives, then we have to use three dots ...
to indicate the end of doc 1 (and the start of potential directives preceding doc 2) to the parser. For example:
doc 1
...
%TAG !bar! !bar-types/
---
doc 2
该规范适用于 yaml 解析器实现者.但是,我发现这篇文章从用户的角度来看更容易阅读.
The spec is good for yaml parser implementers. However, I find this article easier to read from a user perspective.
这篇关于为什么 ---(3 个破折号/连字符)在 yaml 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!