問題描述
我正在使用snakeYaml 將某些配置/屬性值解析為配置對象.
I am using snakeYaml to parse certain configuration/property values to a Configuration object.
我的 yaml 文件看起來像這樣 -
My yaml file looks like this -
#Thread
batchLimit: 1000
threadCountLimit: 2
#Some More Config
key: value
#MAP
keyMapping: <What goes here?>
我的配置類看起來像這樣 -
My Configuration class looks like this -
public class Configuration{
int batchlimit;
int threadCountLimit;
...
Map<String,String> keyMapping;
}
如何在 YAML 文件中定義 keyMapping
使其直接通過 SnakeYAML 讀取?
How do I define the keyMapping
in the YAML file so it reads directly through SnakeYAML?
推薦答案
如下所示:
#MAP
keyMapping:
key1: value1
key2: value2
通常 YAML 格式自然支持鍵值對.查看以下教程(僅作為示例):https://github.com/Animosity/CraftIRC/wiki/Complete-idiot's-introduction-to-yaml
Generally YAML format has natural support of key-value pairs. Take a look on the following tutorial (just for example): https://github.com/Animosity/CraftIRC/wiki/Complete-idiot's-introduction-to-yaml
或者只是谷歌yaml map"了解更多詳情.
Or just google "yaml map" for more details.
這篇關于如何在 YAML 文件中為簡單的 POJO 定義映射?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!