检查变量是否为VTL中的数字 [英] Checking whether the variable is a number in VTL

查看:35
本文介绍了检查变量是否为VTL中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览了 Velocity Template Language 的文档,如何检查变量是 int 类型还是 string 类型以及如何与 VTL 中的正则表达式进行比较,请指导我

Walked through the docs of Velocity Template Language, How could one check that whether a variable is of type int or string and how to compare with regular expressions in VTL, please guide me

推荐答案

Velocity 在上下文中保存对象.您可以将变量作为字符串进行检查.

Velocity holds objects in context. You can check your variable as a String.

在速度方面,您可以像 Java 一样使用正则表达式,使用 $ 获取上下文中的变量.

In velocity you can use regular expression as Java using $ for getting variable in context.

 $variableName.matches("^-?\\d+$");

你也可以通过比较 "java.lang.Integer"${variableName.class.name}

Also you can check if it's an Integer by comparing "java.lang.Integer" to ${variableName.class.name}

这篇关于检查变量是否为VTL中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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