package com.example.demo3;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@ConfigurationProperties(prefix = “person”)//他会自动的去yml文件中找到你的配置
public class demothree {
private String name;
private String age;
@RequestMapping("/three")
@ResponseBody
public String three(){
return name+" ,"+age;
}
//get set方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
yml文件
#配置对象
person:
name: lisi
addr: chengdu
age: 18