且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Velocity 模板中将字符串转换为整数?

更新时间:2023-02-03 08:47:02

啊哈!去过那里.

#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.