1.基本语法 2.数据类型 3.实际演示
(1)Person中的配置如下
@Data
@ToString
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private Integer age;
private Boolean boss;
private Date birthday;
private Pet pet;
private String [] interests;
private List<String> animals;
private Set<Double> salary;
private Map<String,Object> score;
private Map<String,List<String>> allPets;
}
(2)Pet中的配置如下
@Data
@ToString
public class Pet {
private String p_name;
private Double weight;
}
(3)application.yaml中的配置如下
person:
name: malong
age: 21
boss: true
birthday: 1452/5/6
#interests: [篮球,羽毛球]
interests:
- 篮球
- 足球
- 15
animals: [羊儿,猫]
#score:
#english: 99
#math: 100
score: {english:100,math:99}
salary:
- 898888
- 455555
pet:
p_name: tom
wejght: 4
allPets:
sick:
- {p_name:龙,welght:22}
- p_name: 虎
weight: 583
- p_name: 咪咪
weight: 10
healthy:
#- [{p_name:ma,weight:25},{p_name:ml,weight:25}]
- {p_name:ma,weight:25}
- {p_name:ml,weight:25}
(4)controller中的配置如下
@RestController
public class hello_controller {
@Autowired
Person person;
@RequestMapping("/hello")
public Person person(){
return person;
}
}
(5)启动主程序验证即可成功
|