0.1实体类
@Component//标记为springboot组件
@ConfigurationProperties(prefix = "people")//绑定yml配置文件 注意参数的首写字母小写
public class People {
String name;
int age;
Date birth;
Map maps;
List
02.yml配置文件
注:yml不区分大小写,但可以使用松散命名,如nameName在yml中可写作name-name(虽然直接写成namename也行)
server:
port: 8080
people:
name: alan
age: 3
birth: 2019/09/01
maps: {k1: v1,k2: v2,k3: v3}
lists:
- code
- girl
- game
cat:
name: Kayn
age: 3
03.测试类
@SpringBootTest(classes = DemoApplication.class)//标记为springboot测试类 并指明Application类
public class anythingTest {
@Autowired//注入yml配置文件中的数据
private People people;
@Test
public void anything(){
System.out.println(people);
}
}
运行效果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)