Velocity 页面加减运算

需在VM页面中进行加减运算,如

1
$!row.buyNum - $!row.sellNum

在页面上打印出来就是 

3-0

然后不知道怎么用Velocity进行页面的加减运算,问了一下度娘,也找到答案

1
#set($tihuo=$!row.buyNum - $!row.sellNum)
1
是自己在页面随意定义的变量,用来保存计算结果的,然后直接在页面上写上下面的代码就行了
1
$tihuo

也可以 这样 #set($i=$math.sub($velocityCount,1))

 

	<!-- $math.add("10","4") 14 $math.sub("100","20") 80 $math.mul("11","7") 
		77 $math.div("100","5") 20 $math.idiv("100","5") 20 $math.pow("2","5") 32 
		$math.mod("13","5") 3 $math.max("99","16") 99 $math.min("99","16") 16 $math.abs("-99") 
		99 \$math.cell("99.26") $math.cell("99.26") $math.floor("99.26") 99 $math.random 
		0.7663665545444911 $math.random("1","10") 2 $math.roundTo("2","5") 5.0 $math.toInteger("15") 
		15 $math.toDouble("15") 15.0 $math.toNumber("15") 15 -->
	<tool>
		<key>math</key>
		<scope>application</scope>
		<class>org.apache.velocity.tools.generic.MathTool</class>
	</tool>

 

posted @ 2022-01-10 19:47  锐洋智能  阅读(307)  评论(0编辑  收藏  举报