使用yaml给实体类赋值(推荐)
创建一个实体类人类,然后写入属性字段,并且让为了让application.yaml文件可以读取到必须加入注解进行绑定
@ConfigurationProperties(prefix = “person”)这样yaml文件就可以找到配置类了
package com.xxr.dao;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private String sex;
private int age;
private Map<String,Object> map;
public Person() {
}
public Person(String name, String sex, int age, Map<String, Object> map) {
this.name = name;
this.sex = sex;
this.age = age;
this.map = map;
}
public Map<String, Object> getMap() {
return map;
}
public void setMap(Map<String, Object> map) {
this.map = map;