我正在运行一个spring boot项目,我需要动态解析一个错误代码,但我已经意识到如果键是整数类型,它将返回null。有没有办法解析YAML文件中的整数键
解析此属性不起作用
errorcode:
00001: An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
Howver Parsing此属性有效
errorcode:
ONE: An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
我正在尝试使用
读取此属性import org.springframework.core.env.Environment;
@Autowired
private Environment environment;
error= environment.getProperty("errorcode.ONE") Works
error= environment.getProperty("errorcode.00001") --Doesn't works
简而言之,如果一个整数被用作键,则YAML文件将值返回为null。一种解决方法是以这种方式使用密钥,如下所示,但任何更好的想法?
error
code-001:
答案 0 :(得分:0)
可以通过在yaml中将该数字指定为字符串来解决。喜欢,
错误代码:
'00001': An error occurred whilst trying to process your request. We would like to apologise for the inconvenience.
这对我有用。
答案 1 :(得分:-1)
从yaml中读取所有字符串,并将整数值替换为非整数值。将具有非整数值的类反序列化为变量。