web123456

Yaml format, bind data to Java classes

package cn.bitqian.entity; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; import javax.validation.constraints.Email; import java.util.List; import java.util.Map; /** * @author echo lovely * @date 2020/9/26 21:46 */ @Component // Corresponding prefix @ConfigurationProperties(prefix = "person") // setter/getter corresponds to yaml @Validated // Data verification public class Person { @Email(message = "Must be in mailbox format") private String personName; private Boolean happy; private Integer age; private Map<String, Object> maps; private List<Object> hobbyList; private Dog dog; public Person() {} public Person(String name, Boolean happy, Integer age, Map<String, Object> maps, List<Object> hobbyList, Dog dog) { this.personName = name; this.happy = happy; this.age = age; this.maps = maps; this.hobbyList = hobbyList; this.dog = dog; } public String getPersonName() { return personName; } public void setPersonName(String personName) { this.personName = personName; } public Boolean getHappy() { return happy; } public void setHappy(Boolean happy) { this.happy = happy; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public Map<String, Object> getMaps() { return maps; } public void setMaps(Map<String, Object> maps) { this.maps = maps; } public List<Object> getHobbyList() { return hobbyList; } public void setHobbyList(List<Object> hobbyList) { this.hobbyList = hobbyList; } public Dog getDog() { return dog; } public void setDog(Dog dog) { this.dog = dog; } @Override public String toString() { return "Person{" + "personName='" + personName + '\'' + ", happy=" + happy + ", age=" + age + ", maps=" + maps + ", hobbyList=" + hobbyList + ", dog=" + dog + '}'; } }