velocity截取过长的字段值

问题:页面列表展示时,某个字段的值超长,影响页面的整体样式

解决:Velocity中支持宏定义,宏相当于一个函数

在公共的宏页面中定义宏

#macro(cutoff $str)
	#if($str.length()>7)
		#set($str=$str.substring(0,7))
		$str...
	#else
		$!{str}
	#end
#end


在调用需要使用该宏的页面
 <td title="$!{permission.permission}">#cutoff($!{permission.permission})</td>


说明:其中title的作用,鼠标移到该列上,有完整的数据显示

你可能感兴趣的:(velocity)