在springboot配置文件需要使用字符串类型的数值时候,有时候直接写一个0开头的数值,例如001。配置生效之后,打印配置参数时候发现不对,输出的是数值1。
而yml中配置的:000000,输出的是:0
public class ConstructYamlInt extends AbstractConstruct { public ConstructYamlInt() { } public Object construct(Node node) { String value = SafeConstructor.this.constructScalar((ScalarNode)node).toString().replaceAll("_", ""); int sign = 1; char first = value.charAt(0); if (first == '-') { sign = -1; value = value.substring(1); } else if (first == '+') { value = value.substring(1); } int basex = true; if ("0".equals(value)) { return 0; } else { byte base; if (value.startsWith("0b")) { value = value.substring(2); base = 2; } else if (value.startsWith("0x")) { value = value.substring(2); base = 16; } else { if (!value.startsWith("0")) { if (value.indexOf(58) == -1) { return SafeConstructor.this.createNumber(sign, value, 10); } String[] digits = value.split(":"); int bes = 1; int val = 0; int i = 0; for(int j = digits.length; i < j; ++i) { val = (int)((long)val + Long.parseLong(digits[j - i - 1]) * (long)bes); bes *= 60; } return SafeConstructor.this.createNumber(sign, String.valueOf(val), 10); } value = value.substring(1); base = 8; } return SafeConstructor.this.createNumber(sign, value, base); } } }
解决方法:
config: "001" 或者 config: "000000"
https://www.cnblogs.com/i-tao/p/16865913.html
标签:return,配置文件,000000,int,value,sign,substring,base,springboot From: https://www.cnblogs.com/achengmu/p/18358610