Maven 原型所需的属性编号 [英] Maven archetype required property number
问题描述
我有一个使用包含数字的 requiredProperty
的 Maven archtype,但速度变量是字符串.因此,在我的模板中,我无法测试此属性是否大于数字:
I have a Maven archtype that use a requiredProperty
that contains a number, but the velocity variable are string. So, in my template I can't test if this property is greater than a number:
#if( $myVar gt 5 )
我已经测试了以下解决方案而没有成功.
I have tested the following solution without success.
我也试过这个:
#set( $intVar = Integer.parseInt($myVar) )
这在原型一代也失败了.
That's also fail at the archetype generation.
有什么建议吗?
推荐答案
您不能从 Velociy 引用类,因此 Integer.parseInt
将不起作用.但是,由于在 Java 中任何静态方法都可以作为实例方法调用,而 Velocity 只是 Java 的伪装,因此您可以对任何整数调用 parseInt
.所以你可以试试这个技巧:
You can't reference classes from Velociy, so Integer.parseInt
won't work. However, since in Java any static method can be called as an instance method, and Velocity is just Java in disguise, you can call parseInt
on any integer. So you can try this trick:
#if ($myVar.length().parseInt($myVar) gt 5)
您得到一个整数,从您假设拥有的一个变量开始,$myVar
.
You're getting hold of an integer starting from the one variable that you're assuming you have, $myVar
.
这篇关于Maven 原型所需的属性编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!