Velocity模板项目使用案例

本文分享了在公司项目中使用Velocity模板的实际案例,包括如何利用if条件语句进行逻辑判断,以及如何使用$!date.format()方法进行时间格式化为'yyyy年MM月dd日'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前面已经转载介绍了VM模块的使用,下面就贴几个公司开发的案例吧吐舌头

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>中标通知书 </title>
	<style type="text/css">
	body {
		font-family: "宋体";
		font-size: 10.5px;
		line-height: 150%;
		font-weight: normal;
		color: #000000;
		background-color: #FFF;
		text-align: center;
		margin: 20px;
		padding: 20px;
		height: auto;
		width:auto;
	}
	table {
		width:697px;
		height:auto;
		margin:0 auto;
		border:0.2px solid #000000;
	}
	tr{
		line-height: 40px;
	}
	td{
		height:30px;
		border:0.2px solid #000000;
		}
	.highline{
		line-height: 50px;
		text-align: left;
	}
	.highline td{
	    height: 50px;
	    border-top:0px;
	}
	.content_left{
		padding:5px;
	}
	.list{
		list-style-type:none;
		}
	.font24{
		font-size:24px;
		font-weight:bold;
		padding:20px;
		}
	.title{
		text-align:left;
		width:697px;
		height:30px;
		margin:0 auto;
		}
	.right_title150{
		margin-right:150px;
		}
	.right_title10{
		margin-right:10px;
		}
	.right_title40{
		margin-right:40px;
		}
	.vertical_8{
		padding:8px
	}
	.noborder_u_d_l_r{
		border-bottom-width:0px; 
		border-top-width:0px; 
		border-left-width:0px; 
		border-right-width:0px;
		border-bottom-color:#FFFFFF;
	}
	.inner_noborder_u_d_l_r{
		border-bottom-width:0px; 
		border-bottom-color:#FFFFFF;
		border-top-width:0px; 
		border-top-color:#FFFFFF; 
		border-left-width:0px; 
		border-left-color:#FFFFFF; 
		border-right-width:0px;
		border-right-color:#FFFFFF;
	}
	.bottom{
		text-align:left;
		width:697px;
		height:180px;
		}
	</style>  
</head>
<body>
	<span id="back_to_top"></span>
	<ul class="list">
	<li class="font24">中标通知书</li>
	</ul>
	<div class="title">
		<table style="border:0px;">
			<tr>
				<td style="text-align:left; border-bottom-width:0px; border-top-width:0px; border-left-width:0px; border-right-width:0px;border-bottom-color:#FFFFFF"></td>
				<td style="text-align:right; border-bottom-width:0px; border-top-width:0px; border-left-width:0px; border-right-width:0px;border-bottom-color:#FFFFFF"></td>
			</tr>
		</table>
	</div>
	<div>
		<table border="1" cellspacing="0" cellpadding="0" width="652">
		  <tr>
		    <td width="150"><p align="center">工程名称 </p></td>
		    <td width="200" colspan="2"><p align="center">$!projectInfo.projectName</p></td>
		    <td width="100"><p align="center">招标编号 </p></td>
		    <td width="200"  colspan="2"><p>$!projectInfo.projectCode</p></td>
		  </tr>
		  <tr>
		    <td width="150"><p align="center">工程建设地址 </p></td>
		    <td width="470" colspan="5"><p>
			     #if ('SBJ' == $!projectExtra.constructionLocation) 
					    北京市
					    #end
				 #if ('DC' == $!projectInfo.constructionLocation) 
				 	    东城区
				 	    #end
				 #if ('XC' == $!projectExtra.constructionLocation) 
					    西城区 
					    #end
				 #if ('CY' == $!projectExtra.constructionLocation) 
					    朝阳区
					    #end
				 #if ('HD' == $!projectExtra.constructionLocation) 
					    海淀区
					    #end
				 #if ('FT' == $!projectExtra.constructionLocation) 
					    丰台区
					    #end
				 #if ('SJS' == $!projectExtra.constructionLocation) 
					    石景山区
					    #end
				 #if ('MTG' == $!projectExtra.constructionLocation) 
					    门头沟区
					    #end
				 #if ('FS' == $!projectExtra.constructionLocation) 
					    房山区
					    #end
				 #if ('DX' == $!projectExtra.constructionLocation) 
					    大兴区
					    #end
				 #if ('TZ' == $!projectExtra.constructionLocation) 
					    通州区
					    #end
				 #if ('SY' == $!projectExtra.constructionLocation) 
					    顺义区
					    #end
				 #if ('CP' == $!projectExtra.constructionLocation) 
					    昌平区
					    #end
				 #if ('PG' == $!projectExtra.constructionLocation) 
					    平谷区
				 #end
				 #if ('HR' == $!projectExtra.constructionLocation) 
					    怀柔区
				 #end
				 #if ('MY' == $!projectExtra.constructionLocation) 
					    密云县
				 #end
				 #if ('YQ' == $!projectExtra.constructionLocation) 
					    延庆县
				 #end
		    	$!projectExtra.constructionLocationDes</p></td>
		  </tr>
		  <tr>
		    <td width="150"><p align="center">批准总投资额 </p></td>
		    <td width="180"><p align="center">$!number.format("#0.0000",$!projectInfo.investmentSum) 万元</p></td>
		    <td width="140" colspan="2"><p align="center">批准总建筑面积 </p></td>
		    <td width="150" colspan="2"><p>$!number.format("#0.00",$!projectExtra.buildArea) ㎡</p></td>
		  </tr>
		  <tr>
		    <td width="150"><p align="center">中标单位名称 </p></td>
		    <td width="470" colspan="5"><p align="center">$!resultLetter.pubOrgName</p></td>
		  </tr>
		  <tr>
		    <td width="150"><p align="center">中标价 </p></td>
		    <td width="180"><p>$!number.format("#0.00",$!resultLetter.pubRealPrice) 元</p></td>
		    <td width="140" colspan="2"><p align="center">确定中标日期 </p></td>
		    <td width="150" colspan="2"><p>$!date.format('yyyy年MM月dd日',$!{resultLetter.signTime})</p></td>
		  </tr>
		  <tr>
		    <td width="150"><p align="center">中标方案需要说明的问题 </p></td>
		    <td width="470" colspan="5"><p align="center">$!resultLetter.bidInstruction</p></td>
		  </tr>
		  <tr>
		    <td width="290" colspan="3">
				<div style="padding-left:5px;height:150px">法人代表:(签章)</div>
			</td>
			<td width="330" colspan="3">
				<div style="padding-left:5px;height:135px">招标单位:(盖章)</div>
				 #if (!$resultLetter.submitTime) 
			   		 <div style="float:right;padding-right:50px;padding-bottom:5px;">      年      月       日</div>
			    #else
			    	 <div style="float:right;">$!date.format('yyyy年MM月dd日',$!{resultLetter.submitTime})</div>
			    #end
			</td>
		  </tr>
		</table>
		<div class="bottom">
		    <table style="border:0px;">
				<tr>
					<td class="noborder_u_d_l_r" style="text-align:left;" colspan="2">注:本表一式四份,招标单位、中标单位、代理机构及管理部门各一份。</td>
				</tr>
				<tr>
					<td class="noborder_u_d_l_r" style="text-align:left;" colspan="2"><span style="color:#FFFFFF;">   </span>申报单位应对所报材料真实性负责。</td>
				</tr>
		    </table>
		</div>
	</div>
</body>
</html>
这个案例中使用到了

1.if判断的使用

#if ('CY' == $!projectExtra.constructionLocation) 
	 朝阳区
 #end

2.金额样式$!number.format("样式",获取的值)
$!number.format("#0.0000",$!projectInfo.investmentSum)

3.时间格式$!date.format('yyyy年MM月dd日',获取对应的数值)

$!date.format('yyyy年MM月dd日',$!{resultLetter.signTime})

4.if else end 非空判断
 #if (!$resultLetter.submitTime) 
			   		 <div style="float:right;padding-right:50px;padding-bottom:5px;">      年      月       日</div>
			    #else
			    	 <div style="float:right;">$!date.format('yyyy年MM月dd日',$!{resultLetter.submitTime})</div>
			    #end
5.if else end 判断

 <tr>
		    <td width="76"><p align="center"><strong>招标项目 </strong></p></td>
		    <td width="592" colspan="3"><p>
		          勘  察
		    #if ('KC' == $!projectInfo.tenderCategory) 
			    ■ 
			#else
			    □ 
			#end
		    	      
		    	设  计 
		    #if ('SJ' == $!projectInfo.tenderCategory) 
			    ■ 
			#else
			    □ 
			#end</p></td>
		  </tr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值