Velocity页面中输出时间年月

问题:注册页面要求有创建时间的选项添加,年为至今为止

实现:在java中处理,传值到VM中,利用#foreach遍历list

      开始时觉得这样实现很好,但偶然间发现,太笨了,直接用Velocity就可以实现

代码:

								
##获取当前年份
#set($year=$!date.format('yyyy',$date))
#set($Integer=0)
<select name="foundYear">
<option value="">请选择</option>
#foreach($i in [$Integer.parseInt($year)..1830])
#set($_i=$i+"")
<option value="$i" #if($!brandDto.foundYear == $_i) selected = "selected" #end>$i</option>
#end
</select>
<select name="foundMonth">
<option value="">请选择</option>
#foreach($j in [1..12])
#set($j_="")
##格式化至少两位十进制数字,如05,而不是5
#set($j_=$j_.format("%02d",$j))
<option value="$j_" #if($!brandDto.foundMonth == $j_) selected = "selected" #end>$j_</option>
#end
</select>

猜你喜欢

转载自mingyundezuoan.iteye.com/blog/2212624
今日推荐