我是靠谱客的博主 怕黑钢笔,这篇文章主要介绍关于SpringBoot yaml key为中文时的问题,现在分享给大家,希望可以做个参考。

关于SpringBoot yaml key为中文时的问题

在使用@ConfigurationProperties 进行注入时,向注入一个类似于下方的参数

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@ConfigurationPerproties("test") class test { List<Map<String,Dog>> dogs; } class Dog { private String name; private Integer id; public void setName(String name) { this.name = name; } public void setId(Integer id) { this.id = id; } }

在配置的时候使用中文为key 总是会有问题 , 感觉有非常奇怪的错误 , 会显示无法转换类

后来看到使用 "[]"将中文引起来就可以了, 引号与[] 都不可以少

复制代码
1
2
3
4
5
6
7
8
9
10
test: dogs: - "[二楼]": name: 123 id: 12 - we: name: 345 id: 45

记录一下 , 防止忘掉, 找了大半天呢…

最后

以上就是怕黑钢笔最近收集整理的关于关于SpringBoot yaml key为中文时的问题的全部内容,更多相关关于SpringBoot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部