禁用/转换 Java 使大数字变小? (1000,000,0000 到 1E10) 使用 SPEL 表达式

问题描述

我正在使用 Spring SPEL 从 xml 消息中使用 XPath 提取值 10000000000。但是,它以科学记数法显示为 1E10,但我想保持相同的格式 (10000000000)。

如何使用 SPEL 语言表达式实现这一点?

#derivedValue = 从 XPath 中提取的值为 10000000000

我尝试在如下转换规则中使用 java DecimalFormat 但没有工作并抛出拼写异常:

new java.text.DecimalFormat.getIntegerInstance().format((T(java.lang.Double)).parseDouble(#derivedValue)

解决方法

longValue() 上使用 Double

像这样使用 Spring Integration 的 #xpath 函数...

@Bean
public ApplicationRunner runner(BeanFactory bf) {
    return args -> {
        Object value =
                new SpelExpressionParser()
                        .parseExpression("#xpath(#root,'/foo','number').longValue()")
                        .getValue(IntegrationContextUtils.getEvaluationContext(bf),"<foo>10000000000</foo>");
        System.out.println(value);
    };
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...