student:
name: god
age: 10
happy: true
birthday: 2099/09/09
mapscores:
math: 100
eng: 100
chinese: 100
hobbylist:
- swimming
- bycicle
- tennis
- basketball
friend:
name: friendname
package com.hellosrc.springconf.bean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Author: cui song lin
* @Description:
**/
@Component
@ConfigurationProperties(prefix = "student")
public class Student {
String name;
Integer age;
Boolean happy;
Date birthday;
Map<String, Integer> mapscores;
List<String> hobbylist;
Friend friend;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Boolean getHappy() {
return happy;
}
public void setHappy(Boolean happy) {
this.happy = happy;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Map<String, Integer> getMapscores() {
return mapscores;
}
public void setMapscores(Map<String, Integer> mapscores) {
this.mapscores = mapscores;
}
public List<String> getHobbylist() {
return hobbylist;
}
public void setHobbylist(List<String> hobbylist) {
this.hobbylist = hobbylist;
}
public Friend getFriend() {
return friend;
}
public void setFriend(Friend friend) {
this.friend = friend;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", happy=" + happy +
", birthday=" + birthday +
", mapscores=" + mapscores +
", hobbylist=" + hobbylist +
", friend=" + friend +
'}';
}
}
package com.hellosrc.springconf.bean;
import org.springframework.stereotype.Component;
/**
* @Author: cui song lin
* @Description:
**/
@Component
public class Friend {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.hellosrc.springconf;
import com.hellosrc.springconf.bean.Student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringconfApplicationTests {
@Autowired
Student student;
@Test
void contextLoads() {
System.out.println(student);
}
}
测试结果