- 导入
SpringBoot
的snakeyaml
解析包 - 编写
yaml
文件 - 编写
yaml
文件对应的class
- 编写
main
进行获取
导入
SpringBoot
的snakeyaml
解析包
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
</dependency>
编写
yaml
文件
id: 110
name: 'stuName'
gender: '男'
clas:
id: 110
name: 'classesName'
describe: 'describe'
编写
yaml
文件对应的class
public class Student {
private Integer id;
private String name;
private String gender;
private Classes clas;
// getter(), setter(), toString();
}
class Classes {
private Integer id;
private String name;
private String describe;
// getter(), setter(), toString();
}
编写
main
进行获取
public static void main(String[] args) {
Yaml yaml = new Yaml();
Student result = yaml.loadAs(thisClass.class.getClassLoader()
.getResourceAsStream("springboot.yaml"),
Student.class);
System.out.println(result);
}