yml内容
yml: login: name: zhangsan age: 18 pass: 123456
方式一:
创建实体类
@Configuration @ConfigurationProperties(prefix = "yml.login") @Data public class YmlVo { private String name; private String age; private String pass; }
获取
@Autowired YmlVo ymlVo; @Test void contextLoads() { System.out.println("年龄:"+ymlVo.getAge()); //年龄:18 }
方式二:
@Value("${yml.login.name}") private String name; @Test void contextLoads() { System.out.println("姓名:"+name); //姓名:zhangsan }
标签:String,自定义,private,获取,login,yml,name From: https://www.cnblogs.com/xbinbin/p/17594024.html