map hash object 方式1: k:{k1:v1,k2:v2,k3:v3}
方式二
K:
K1: V1
K2: V2
K3: V3
注意冒号后面一定要写空格,再写值
array list queue
方式二 方式1 k::[v1,v2,v3]
K:
- v1,
- v2
用在yaxml文件中,例子:
application.yaml
person:
boss: true
birth: 2020/10/10
age: 18
pet:
name: pet1
weight: 99.99
inerests:
-insert1
-insert2
-insert3
animal: [animal1,animal2,animal3]
score:
first: 30
second: 40
third: 50
first2: 30
second2: 40
third2: 50
salarys:
- 5000
- 6000
- 7000
allpets:
dead: [{name: name1dead,weight: 100},{name: namedead2,weight: 200}]
live:
- { name: 汤姆猫 }
- { name: jerry,weight: 47 }
user-name: mike
pserson
package com.example.springdemo2.pojo;
import lombok.Data;
import lombok.ToString;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import java.util.*;
@ConfigurationProperties(prefix = "person")
@Component
@ToString
@Data
public class Person {
private String userName;
private Boolean boss;
private Date birth;
private Integer age;
private Pet pet;
private String[] interests;
private List<String> animal;
private Map<String, Integer> score;
private Set<Double> salarys;
private Map<String, List<Pet>> allPets;
}
注意在yml中userName:和 user- name是一样的, -可以让后面的字母大写。
可以安装一个插件
这个插件可以使我在写配置文件的属性名时有提示
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
因为这个包只有在写代码时才会用到,所以注意在导出包时不要把这个包也导出了,会增大包的大小,而且用不到这个包。
设置不导出的包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- 配置打包插件-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<!-- 配置在打包时忽略这个类,他是作用于编码阶段,将他方进包中,一点用都没有,只会使包变大-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>