如何在 Velocity 模板中将字符串转换为整数? [英] How to convert string into integer in the Velocity template?
本文介绍了如何在 Velocity 模板中将字符串转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Velocity 模板文件,其中包含来自 XML 的数据.我想将字符串转换为整数类型.
I have a Velocity template file which has the data from XML. I want to convert the string into integer type.
我该怎么做?
推荐答案
啊哈!去过那里.
#set($intString = "9")
#set($Integer = 0)
$Integer.parseInt($intString)
这样做会使用 Java 底层速度.$Integer 变量只不过是一个 java Integer 对象,您可以使用它来访问 .parseInt
Doing this uses the java underlying velocity. The $Integer variable is nothing more that a java Integer object which you can then use to access .parseInt
以上代码用于演示.当然有优化的方法.
The above code is for demonstration. Of course there are ways to optimize it.
这篇关于如何在 Velocity 模板中将字符串转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文