例子:
配置对象:(在yml中的配置)
person: name: "王五" age: 13 sex: "男" happy: "打球"
使用配置的对象:
@Component @ConfigurationProperties(prefix = "person") @Data public class Person { String name; int age; String sex; String happy; }
结果:
@RestController public class PersonController { @Resource Person person; @RequestMapping(value = "/getPerson") public Person getP(){ return person; } }
结果图片: