如何在属性文件中将下划线包含在数字值中?

4

在Spring的@Value注解中,如果我在数值属性中包含下划线_,该如何处理?如果我在属性值中包含_,Spring会抛出TypeMismatchException异常。

.properties文件示例:

min-score=20_000

Java类:

@Value("${min-score}")
private int minScore;
1个回答

5
在你的@Value注释中使用Spring EL来替换_字符:
@Value("#{'${min-score}'.replace('_','')}")
private int minScore;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接