【问题标题】:How to include _ in a numeric value in properties file?如何在属性文件的数值中包含 _?
【发布时间】:2018-12-07 23:20:51
【问题描述】:

如何在我的数值属性中添加_(下划线),同时在Spring 中注入@Value 注释?如果我在值中包含_,Spring 会抛出TypeMismatchException

.properties 文件:

min-score=20_000

java类:

@Value("${min-score}")
private int minScore;

【问题讨论】:

    标签: java spring properties el readability


    【解决方案1】:

    @Value 注释中使用 Spring EL 替换 _ 字符:

    @Value("#{'${min-score}'.replace('_','')}")
    private int minScore;
    

    【讨论】:

      猜你喜欢
      • 2014-01-17
      • 2016-11-02
      • 2011-08-08
      • 1970-01-01
      • 2016-08-24
      • 2017-07-15
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多