在Spring的@Value
注解中,如果我在数值属性中包含下划线_
,该如何处理?如果我在属性值中包含_
,Spring会抛出TypeMismatchException
异常。
.properties文件示例:
min-score=20_000
Java类:
@Value("${min-score}")
private int minScore;
在Spring的@Value
注解中,如果我在数值属性中包含下划线_
,该如何处理?如果我在属性值中包含_
,Spring会抛出TypeMismatchException
异常。
.properties文件示例:
min-score=20_000
Java类:
@Value("${min-score}")
private int minScore;
@Value
注释中使用Spring EL来替换_
字符:@Value("#{'${min-score}'.replace('_','')}")
private int minScore;