问题
要求:打印数据,当数据内容小于10行时,打印数据,在数据末尾加空行。
(虽然是很简单的问题,表示当时磨了一个晚上2h)
需要解决:(1)不知道数据有多少行
(2)当数据<10行时候,打印多少行空格
(3)velocity怎么写
思考方式:①判断数据是不是<10,②打印数据,③打印10-数据.size()的空行
参考:http://www.360doc.com/content/13/0401/13/10825198_275274565.shtml
velocity基础教程(因为自己基础不扎实,不知道如何下手写,也磨了很久)
数组写法(例子):
#set ( $arr = [0..1] )
#foreach ( $i in $arr )
$i
#end
输出结果: 0 1
(例子不需要太难,重点是理解与运用)
解答:
(这里List是后台查找返回到页面的数据,不清楚具体有多少,因此加一个if判断)
#if($List.size()<10)
#set( $arrMax = 10-$List.size())
#set( $arr = [1..$arrMax])
#foreach( $i in $arr)
<tr>
<td align="center" width="153px;" height="50px;"></td>
<td align="center" width="153px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="103px;"></td>
</tr>
#end
#end
输出结果:
问题
要求:打印数据,当数据内容小于10行时,打印数据,在数据末尾加空行,空行的的第一行第一列写上“以下空白”。
(用了一种比较挫的方法,能得到结果)
解答:①空行的第一行第一列写上“以下空白”,②后续打印 9-数据.size()
(同上List也是后台查询的数据)
#if($List.size()<10)
#set( $arrMax = 9-$List.size())
#set( $arr = [1..$arrMax])
<tr>
<td align="center" width="153px;" height="50px;">以下空白</td>
<td align="center" width="153px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="103px;"></td>
</tr>
#foreach( $i in $arr)
<tr>
<td align="center" width="153px;" height="50px;"></td>
<td align="center" width="153px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="83px;"></td>
<td align="center" width="103px;"></td>
</tr>
#end
小结:(哎╮(╯▽╰)╭真心不想写什么高大上的东西)其实都是基础,基础不扎实,走了好多弯路呢·~~引以为戒