1、person.properties
person.last-name=李四
person.age=23
person.birth=2020/5/2
person.boss=false
person.map.name=中国
person.map.capatial=北京
person.list=a,b,c
person.dog.name=虎子
person.dog.age=2
2、实体类Person
package com.dc.springboot01.bean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author dc
* @date 2020/5/2 - 10:41
*/
//注明该类为组件
@Component
//@ConfigurationProperties(prefix = "person")批量注入对象的属性的值
//@Value 只能逐个注入对象的属性的值
@ConfigurationProperties(prefix = "person")
@PropertySource(value = {"classpath:person.properties"})
public class Person implements Serializable {
private String lastName;
private Integer age;
private boolean boss;
private Date birth;
private Map<String, Object> map;
private List<Object> list;
private Dog dog;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o =&#