spring boot中在yml中配置后如何在Java中使用
作者:互联网
例子:
配置对象:(在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; } }
结果图片:
标签:Java,String,Person,spring,boot,sex,person,public,happy 来源: https://www.cnblogs.com/wang-1206/p/15766076.html