概念
比如我的yml中写的last-name,这个和lastName是一样的,-后面跟着的字母默认是大写的,这就是松散绑定
示例
类代码:
java">public class Person {
private String lastName;
private Integer age;
private Boolean happy;
private Date birth;
private Map<String,Object> maps;
private List<Object> lists;
private Dog dog;
// 有参、无参、Getter和Setter方法、toString()
yml配置:
person:
last-name: ZuY
age: 18
happy: false
birth: 2000/01/01
maps: {k1: v1,k2: v2}
lists:
- code
- girl
- music
dog:
name: 旺财
age: 5
测试代码:
java">@SpringBootTest
class Demo1ApplicationTests {
@Autowired
private Person person;
@Test
void contextLoads() {
System.out.println(person);
}
}
结果: