如何在属性文件的数值中包含_? [英] How to include _ in a numeric value in properties file?

查看:69
本文介绍了如何在属性文件的数值中包含_?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I have _ (underscore) in my numerical property while injecting it with @Value annotation in Spring? If I include _ in my value, Spring throws TypeMismatchException.

.properties文件:

.properties file:

min-score=20_000

java类:

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


推荐答案

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

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

这篇关于如何在属性文件的数值中包含_?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆