1, the basic grammar
1. k :( space) v: designates a pair of key-value pairs ( Note: There must be a space );
2. ** ** spaces of indentation control hierarchy; as long as one is left-aligned data, are the same levels
3. The value written hump and with "-" character is the same value, such as: lastName and last-name are possible
4. Liezi:
server:
port: 8081
path: /hello
Note: The attributes and values are case sensitive
2, the value written
1. literal: Common values (numbers, strings, Boolean)
k: v: literally write directly;
1 without the default string in single or double quotes;
2. String special treatment
"": double quotation marks; not escape special characters string inside; special characters as represented by itself means like
example: name: "zhangsan \ n lisi ": Output; zhangsan wrap lisi
'': single quote; will escape special characters, special characters finally only a common data string
example: name: 'zhangsan \ n lisi ': output; zhangsan \ n lisi
2. Object, Map:
1.k: v: to write the relationship between attributes and values of an object on the next line; Note indent, object or k: v way, pay attention to left-aligned.
example:
friends:
lastName: zhangsan
age: 20
2. inline wording:
friends: {lastName: zhangsan,age: 18}
3. Array (List, Set)
1. - value represents an element in the array,
example:
pets:
- cat
- dog
- pig
2. inline wording
pets: [cat,dog,pig]
Use Cases:
1.yaml file.
person:
lastName: hello
age: 18
boss: false
birth: 2017/12/12
maps: {k1: v1,k2: 12}
lists:
- lysis
- zhaoliu
dog:
name: Puppies
age: 12
2.javaBean:
/** * The value of the attribute of each configuration file is mapped to the component * @ConfigurationProperties: Tell SpringBoot all the attributes and configuration files in this class for the corresponding configuration bind; * 1.prefix = "person": the configuration file for the K value of the person's mapping assignment. * Note 2. ConfigurationProperties the corresponding processor to import a jar * <dependency> * <groupId>org.springframework.boot</groupId> * <artifactId>spring-boot-configuration-processor</artifactId> * <optional>true</optional> * </dependency> * * 3. need javabean poured into the container with @Component. To provide a container of @ConfigurationProperties function; * */ @Component @ConfigurationProperties(prefix = "person") public class Person { private String lastName; private Integer age; private Boolean boss; private Date birth; private Map<String,Object> maps; private List<Object> lists; private Dog dog;