`

为了说明Freemarker Macro做Web页面重用性好的一些代码

阅读更多

 

Well,多标题党啊,不说废话了,上code

 

图片,就看我相册里几个做参考好了。

 

<#macro pagination_for_search style="digg" search_url="search_post.do" 
	totalCount=8>
<#if page?exists>
<#assign cp = page.currentPage />
<#assign npp = page.numPerPage />

<#assign begin = cp - totalCount/2 />

<#assign totalRows = page.totalRows />
<#assign totalPages = page.getTotalPages() />

<#assign targetUrl = "#?1=1&" />
<#if req_url?exists>
	<#assign targetUrl = req_url />
</#if>

<div class="${style}">
	<span class="one">
	${locale.t_row_label?if_exists}:${totalRows}
	</span>
	<span class="one">
	${locale.t_page_label?if_exists}:${totalPages}
	</span>
	<#if (totalPages != 1)>
	<span class=""> 
		<a href="${search_url}?model=${model_whole_name?if_exists}&cp=1&${req_query?if_exists}" 
			title="First Page"><<</a>
	</span>
	</#if>
	
	<#assign count = 0 />
	<#list begin..totalPages as pp>
		<#if (begin <= 0)>
			<#assign begin = begin + 1 />
		<#else>
			<#if (count == totalCount)>
				<#break>
			<#else>
				<#if begin == cp>
					<span class="current" title="Current Page">${cp}</span>
				<#else>
					<a href="${search_url}?model=${model_whole_name?if_exists}&cp=${begin}&npp=${npp}&${req_query?if_exists}" 
						title="Page ${begin}">${begin}</a>
				</#if>
				<#assign begin = begin + 1 />
				<#assign count = count + 1 />
			</#if>
		</#if>
	</#list>
	<#if (totalPages > totalCount)>
	...
		<#if (cp == totalPages)>
			<span class="current" title="Current Page">${cp}</span>
		<#else>
			<a href="${search_url}?model=${model_whole_name?if_exists}&cp=${totalPages}&npp=${npp}&${req_query?if_exists}" 
				title="Last Page">${totalPages}</a>
		</#if>
	
		<#if cp != totalPages>
			<a href="${search_url}?model=${model_whole_name?if_exists}&cp=${cp + 1}&npp=${npp}&${req_query?if_exists}" title="Next Page"> > </a>
		<#else>
			<a href="${search_url}?model=${model_whole_name?if_exists}&cp=${cp}&npp=${npp}&${req_query?if_exists}" title="Next Page"> > </a>
		</#if>
	</#if>
	<span style="color:#aaaadd; margin-right: 2px;">${locale.total_rows_label?if_exists}:<font color="red">${totalRows}</font></span>
	<span style="color:#aaaadd;">${locale.npp_label?if_exists}:</span>
	<select name="pager_npp" onchange="javascript:location.href='${search_url}?model=${model_whole_name?if_exists}&npp=' + this.value + '&${req_query?if_exists}';">
		<option value="10">--</option>
		<option value="5">5</option>
		<option value="10">10</option>
		<option value="15">15</option>
		<option value="20">20</option>
	</select>
	<#if (totalPages > 1)>
	<span style="color:#aaaadd;">${locale.goto_page_label?if_exists}:</span>
	<select name="pager_goto_page" onchange="javascript:location.href='${search_url}?model=${model_whole_name?if_exists}&npp=${npp}&cp=' + this.value + '&${req_query?if_exists}';">
		<option value="1">--</option>
		<#list 1..totalPages as i>
		<option value="${i}">${i}</option>
		</#list>
	</select>
	</#if>
</div>
</#if>
</#macro>
<#-- End Crud Macro: Pagination -->

 

 

<#assign crudUrl="/common/swsj/crud/" />
<#assign beginPath="/common/swsj/common/crud/" />


<#macro body title="" encoding="utf-8" beginPath="/common/swsj/common/crud/">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">

<!-- redirect to target page by refresh http header -->
<#if refresh_url?exists>
<meta http-equiv="refresh" content="2; URL=${refresh_url}" /> 
</#if>

<!-- crud js related -->
<!-- jquery js related -->
<script type="text/javascript" src="${beginPath}js/crud.valid.js"></script>
<script type="text/javascript" src="${beginPath}js/crud.form.js"></script>
<script type="text/javascript" src="${beginPath}js/jquery.js"></script>
<script type="text/javascript" src="${beginPath}js/commons.js"></script>
<script type="text/javascript" src="${beginPath}js/niceforms.js"></script>

<script type="text/javascript" src="${beginPath}js/jquery.maskedinput.pack.js"></script>
<script type="text/javascript" src="${beginPath}js/ui.datepicker.js"></script>
<script type="text/javascript" src="${beginPath}js/flexigrid.js"></script>

<script type="text/javascript" src="${beginPath}js/jquery.tooltip.js"></script>

<script type="text/javascript" charset="utf-8" src="${beginPath}editor/kindeditor/build/kindeditor.js"></script>

<#if ext_js_list?exists>
<#list ext_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>
</#if>

<#if ext_css_list?exists>
<#list ext_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
</#if>
<!-- css related -->
<link href="${beginPath}css/niceforms-default.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/pager.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/ui.datepicker.css" rel="stylesheet" type="text/css" />

<link href="${beginPath}css/crud.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/flexigrid.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/jquery.tooltip.css" rel="stylesheet" type="text/css" />

<title>${title?if_exists}</title>
	<script type="text/javascript">
	$(document).ready(function () {
		// nice forms
		existingLoadEvent();
		NFInit();
		
		<#if datagrid?exists && datagrid != "">
		$('#${datagrid}').flexigrid({
			height:'auto',
			striped:false,
			title:'${datagrid_title?if_exists}'
			});
		</#if>
		
		init_input();
		init_hover();
	});
	</script>
</head>

<body>
<!--
<div id="rhead">
	<div id="rpos"><#if RequestParameters.current_pos?exists>${RequestParameters.current_pos}<#else>${locale.home_label?if_exists}</#if></div>
</div>
-->

<@crud_nav />

<#nested>

</body>
</html>
</#macro>
<#-- End Crud Macro: Page -->

<#macro blank_body title="" encoding="utf-8" beginPath="/common/swsj/common/crud/">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">

<!-- redirect to target page by refresh http header -->
<#if refresh_url?exists>
<meta http-equiv="refresh" content="2; URL=${refresh_url}" /> 
</#if>

<!-- crud js related -->
<!-- jquery js related -->
<script type="text/javascript" src="${beginPath}js/crud.valid.js"></script>
<script type="text/javascript" src="${beginPath}js/crud.form.js"></script>
<script type="text/javascript" src="${beginPath}js/jquery.js"></script>
<script type="text/javascript" src="${beginPath}js/commons.js"></script>
<script type="text/javascript" src="${beginPath}js/niceforms.js"></script>

<script type="text/javascript" src="${beginPath}js/jquery.maskedinput.pack.js"></script>
<script type="text/javascript" src="${beginPath}js/ui.datepicker.js"></script>
<script type="text/javascript" src="${beginPath}js/flexigrid.js"></script>

<script type="text/javascript" src="${beginPath}js/jquery.tooltip.js"></script>

<script type="text/javascript" charset="utf-8" src="${beginPath}editor/kindeditor/build/kindeditor.js"></script>

<#if ext_js_list?exists>
<#list ext_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>
</#if>

<#if ext_css_list?exists>
<#list ext_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
</#if>
<!-- css related -->
<link href="${beginPath}css/niceforms-default.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/pager.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/ui.datepicker.css" rel="stylesheet" type="text/css" />

<link href="${beginPath}css/crud.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/flexigrid.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/jquery.tooltip.css" rel="stylesheet" type="text/css" />

<title>${title?if_exists}</title>
	<script type="text/javascript">
	$(document).ready(function () {
		// nice forms
		existingLoadEvent();
		NFInit();
		
		<#if datagrid?exists && datagrid != "">
		$('#${datagrid}').flexigrid({
			height:'auto',
			striped:false,
			title:'${datagrid_title?if_exists}'
			});
		</#if>
		
		init_input();
		init_hover();
	});
	</script>
</head>

<body>

<#nested>

</body>
</html>
</#macro>
<#-- End Crud Macro: Page Blank -->

 

 

 

 

页面有的是PHP的,不过很多都是从swsj这个以前自己做的一个项目里弄过来的

 

还有几个图,jscharts的

 

<#assign style_arr = {
	"blue":  
		{
			"bar_color": "#42aBdB", 
			"bar_border_color": "#D9EDF7", 
			"title_color": "#8C8383",
			"axis_color": "#777E81",
			"axis_name_color": "#777E81",
			"axis_value_color": "#777E81",
			"grid_color": "#ABABAB",
			
			'pie_title_color': '#7A7A7A',
			'pie_units_color': '#fff',
			'pie_values_color': '#878787'
			},
		
	"magenta":  
		{
			"bar_color": "#42aBdB", 
			"bar_border_color": "#bbb", 
			"title_color": "#8C8383",
			"axis_color": "#ABABAB",
			"axis_name_color": "#858585",
			"axis_value_color": "#858585",
			"grid_color": "#ABABAB"
			},
		
		
	"red":  
		{
			"bar_color": "#42aBdB", 
			"bar_border_color": "#D9EDF7", 
			"title_color": "#8C8383",
			"axis_color": "#777E81",
			"axis_value_color": "#777E81"
			}
} />

<#-- Chart Bar -->
<#macro basic_bar chart_div_id="mybarchart" style="blue" barvalue="false" 
	bar_opacity="0.8" bar_space_ratio="50" axis_width="1">
<#assign theme=style_arr[style] />
<#if !theme?exists>
	<#assign theme=style_arr['blue'] />
</#if>
	
<div id="${chart_div_id}">Loading...</div>
<script type="text/javascript">
	var myData = new Array(['2005', 2], ['2006', 1], ['2007', 3], ['2008', 6]);
	var colors = ['#7979DB', '#7952E9', '#792BC8', '#792BA1'];
	<#nested />
	var myChart = new JSChart('${chart_div_id}', 'bar');
	myChart.setDataArray(myData);
	myChart.colorizeBars(colors);
	
	myChart.setBarColor('${theme.bar_color}');
	myChart.setBarBorderColor('${theme.bar_border_color}');
	myChart.setBarValues(${bar_value});
	myChart.setBarSpacingRatio(${bar_space_ratio});
	myChart.setBarValues(${bar_value});
	
	myChart.setTitleColor('${theme.title_color}');
	
	myChart.setAxisColor('${theme.axis_color}');
	myChart.setAxisNameColor('${theme.axis_name_color}');
	myChart.setAxisValuesColor('${theme.axis_value_color}');
	myChart.setAxisWidth(${axis_width});
	
	myChart.setGridColor('${theme.grid_color}');
	myChart.setBarOpacity(${bar_opacity});
	
	myChart.draw();
</script>

</#macro>
<#-- End Macro Chart Bar -->

<#-- Chart Pie -->
<#macro basic_pie chart_div_id="mypiechart" style="blue">
<#assign theme=style_arr[style] />
<#if !theme?exists>
	<#assign theme=style_arr['blue'] />
</#if>
	
<div id="${chart_div_id}">Loading...</div>
<script type="text/javascript">
	var myData = new Array(['S.1', 20], ['S.2', 70], ['S.3', 30], ['S.4', 60], ['S.5', 80], ['S.6', 10]);
	var colors = ['#898A89', '#767776', '#676767', '#434443', '#B0B1B0', '#9E9F9E'];
	<#nested />
	var myChart = new JSChart('${chart_div_id}', 'pie');
	myChart.setDataArray(myData);
	myChart.colorizePie(colors);
	
	myChart.setTitleColor('${theme.pie_title_color}');
	myChart.setPieUnitsColor('${theme.pie_units_color}');
	myChart.setPieValuesColor('${theme.pie_values_color}');
	myChart.draw();
</script>

</#macro>
<#-- End Macro Chart Pie -->

 

 

 

 

<#assign product_name = "swsj framework view layer">
<#assign product_version = "1.0">
<#assign product_title = "System Powered By SWSJ">

<#assign beginPath = "/common/swsj/common/resource/" />
<#assign default_js_list=["commons.js", "jquery.js", "jquery.cookie.js", "jquery.treeview.js", 
	"chili-1.7.pack.js", "jquery.easing.js", "jquery.dimensions.js", "jquery.accordion.js"]>
<#assign default_css_list=["admin.style.css", "jquery.treeview.css", "theme.css", "flora.accordion.css"]>


<#-- main navigation define 
<#assign app_list = [{"app_code": "ttt", "label": "CRUD演示"}] />
-->

<#-- whole page layout -->
<#macro page_header title="Increx System By SWSJ" 
	encoding="utf-8" beginPath="/common/swsj/resource/">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}" />
<title>${title}</title>

<#list default_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>
<#if ext_js_list?exists>
<#list ext_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>
</#if>

<#list default_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
<#if ext_css_list?exists>
<#list ext_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
</#if>
<style type="text/css">
	html{height:100%; overflow:hidden;}
	body{height:100%;}
</style>

<script>
    var changeNavUrlPrefix = 'index.htm';

	var changeNav = function(str){
		targetUrl = changeNavUrlPrefix + '?role='+str;
		document.location.href = targetUrl;
	}
</script>
<#nested />

</head>
</#macro>

<#macro page_body beginPath="/common/swsj/common/resource/">
<body onresize="resizeFrame();">
<!--页头Begin-->
<div id="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="330"><img src="${beginPath}img/admin/cms_logo.jpg" border="0" /></td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="32" align="right" background="${beginPath}img/admin/top_bg.jpg">
		<table border="0" cellspacing="0" cellpadding="0" style="margin-top:5px;">
          <tr>
            <td width="17" align="center"><img src="${beginPath}img/admin/msg2.jpg" width="10" height="8" border="0"/></td>
            <td width="70" align="left"><a href="javascript:void();" class="channel" id="current_user">${Session.user_status.usercode?if_exists}</a></td>
            <td width="12" height="25" align="center"><img src="${beginPath}img/admin/ico1.gif" border="0"/></td>
            <td width="60" align="left">
			<select onchange="changeNav(this.value);">
				<option value="">ALL</option>

				<#list user.roleList as userRole>
				<#if current_role?exists && current_role == userRole>
				<option value="${userRole}" selected>${userRole}</option>
				<#else>
				<option value="${userRole}">${userRole}</option>
				</#if>
				</#list>
			</select>
			<!--
			<a class="channel" href="index.htm">${locale.refresh_label?if_exists}</a>
			-->
			</td>
            <td width="17" align="center"><img src="${beginPath}img/admin/ico5.jpg" border="0"/></td>
            <td width="60" align="left"><a href="auth/logout.htm" class="channel" onclick="return confirm('${locale.logout_warning?if_exists}');">${locale.logout_label?if_exists}</a></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="95" align="right" background="${beginPath}img/admin/sy_bg.jpg">
				<!--
            	<a href="left.htm?app_code=help" target="leftFrame">Home</a>&nbsp;
				-->
			</td>
			<#-- begin loop application -->
			<#if app_list?exists>
            <#list app_list as app>
			<td width="8"><img src="${beginPath}img/admin/menu_sep.jpg" border="0" /></td>
            <td width="76" align="center" background="${beginPath}img/admin/menu_bg.jpg">
            	<a href="left.htm?app_code=${app.app_code?if_exists}" target="leftFrame">${app.label?if_exists}</a>            
            </td>
            </#list>
            </#if>
            
 			<#if appNavModel?exists>
            <#list appNavModel.subList as app>
			<td width="8"><img src="${beginPath}img/admin/menu_sep.jpg" border="0" /></td>
            <td width="76" align="center" background="${beginPath}img/admin/menu_bg.jpg">
            	<a href="left.htm?app_code=${app.code?if_exists}" title="${app.des?if_exists}" 
            	target="leftFrame">${app.label?if_exists}</a>            
            </td>
            </#list>
            </#if>           
            <#-- end -->
						
            <td background="${beginPath}img/admin/menu_bg.jpg">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="10%" align="center" background="${beginPath}img/admin/msg_bg.jpg"><img src="${beginPath}img/admin/xs.gif" border="0"/></td>
    <td width="10%" background="${beginPath}img/admin/msg_bg.jpg"></td>
    <td width="60%" background="${beginPath}img/admin/msg_bg.jpg"><img src="${beginPath}img/admin/tleft.jpg" width="28" height="26" border="0"/></td>
    <td width="20%" align="center" background="${beginPath}img/admin/tbg.jpg">
    <script language="JavaScript" type="text/javascript">
    	var	today = new Date();
		document.write(today.toLocaleString());
	</script>
	</td>
  </tr>
</table>
<div style="border-top:1px solid #1879B0;"></div>
</div>

<!--页头End-->
<!--主体框架Begin-->
<iframe id="mainFrame" name="mainFrame" src="main.htm" frameborder="0" scrolling="no" style="width:100%;"></iframe>
<!--主体框架End-->
<div style="border-top:1px solid #1879B0;"></div>
<script type="text/javascript">
function resizeFrame() {
	document.getElementById("mainFrame").style.height = document.body.offsetHeight-document.getElementById("top").offsetHeight-1+"px";
}
resizeFrame();
</script>
</body>
</html>
</#macro>


<#macro page_main encoding="utf-8">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}" />
<title></title>
</head>
<frameset cols="180,*" frameborder="0" border="0" framespacing="0">
	<frame src="left.htm" name="leftFrame" noresize="noresize" id="leftFrame" />
	<frame src="" name="rightFrame" id="rightFrame" />
</frameset>
<noframes><body></body></noframes>
</html>
</#macro>

<#macro page_left encoding="utf-8" beginPath="/common/swsj/common/resource/">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}" />
<title></title>
<#list default_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>

<#list default_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
<script type="text/javascript">
$(function(){
		// second simple accordion with special markup
		$('#navigation').accordion({
			autoheight: false,
			active: false,
			header: '.head',
			navigation: true,
			event: 'click',
			animated: 'slide'
		});
});

</script>
</head>
<body class="lbody">
	<#nested />
</body>
</html>
</#macro>

<#macro page_right encoding="utf-8" beginPath="/common/swsj/common/resource/" nav="Home - Welcome" nav_url="">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}" />
<title></title>
<#list default_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>

<#list default_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
<script type="text/javascript">
$(function(){
	
});
</script>
</head>
<body>
<div class="body-box">
<div class="rhead">
	<div class="rpos">
	<#if nav_url == "">
	${nav}
	<#else>
	<a href="${nav_url}">${nav}</a>
	</#if>
	</div>
	<div class="clear"></div>
</div>
<#nested />
</div>
</body>
</html>
</#macro>

 

 

一个文件,三块都出来了,剩下的页面都是以下写法

 

<#import "/macro/zftl-simple.ftl" as page>

<#assign is_simple = true in page />

<#assign ext_css_list = ['plugin/flexigrid.css'] in page />
<#assign ext_js_list = ['jquery.flexigrid.js'] in page />

<#assign req_url = '?m=bbs&a=item_list&module_id=' + module_id />

<@page.page_header title="论坛版块" + module.name>
<script>
	$(document).ready(function () {
//		$('#flex').flexigrid({
//			height:'auto',
//			striped:false,
//			title:'话题列表'
//		});

		$('tr').hover(
			function() {$(this).addClass('tr_focus');},
			function() {$(this).removeClass('tr_focus');}
		);
	});
</script>
</@page.page_header>

<@page.page_body>
<div class="container">
	<h3>${module.sup_name} - ${module.name}</h3>
	<a href="?m=bbs&a=index" title="重新选择讨论版区">返回</a>
	<table width="100%" id="flex">
	 <tr>
	  <td width="30%">话题</td>
	  <td width="10%">作者</td>
	  <td style="text-align: center;">浏览次数</td>
	  <td style="text-align: center;">回复数量</td>
	  <td>发布时间</td>
	  <td></td>
	 </tr>

	 <#list pi.resultList as item>
	 <tr>
		  <td><a href="?m=bbs&a=item_show&item_id=${item.id?if_exists}" 
			title="${item.title?if_exists}">${item.title?if_exists}</a></td>
		  <td>${item.author?if_exists}</td>
		  <td style="color: red; text-align: center;">${item.view_count?if_exists}</td>
		  <td style="color: red; text-align: center;">
		  <#if item.reply_num?exists>${item.reply_num}<#else>0</#if>
		  </td>
		  <td>${item.create_date?if_exists}</td>
		  <td>
		  <#if can_delete?exists>
		  	<a href="bbs.gy?m=bbs&a=item_del&module_id=${item.module_id?if_exists}&id=${item.id?if_exists}"	
					onclick="return confirm('确定要删除么?');">删除</a>
		  </#if>
		  </td>
		 </tr>
	 </#list>
	</table>
	<hr />
	<@page.pagination targetUrl=req_url />
	
</div>
</@page.page_body>

 

 

Well,还有很多,比如为了动态生成Extjs的

<#macro license_head>
/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
</#macro>

<#-- Begin Macro ExtJs Body -->
<#macro ext_js_body>
<@license_head />

Ext.onReady(function(){

<#nested />

});
</#macro>
<#-- End Macro ExtJs Body -->
 

 

 

发了不少了,做过不少东东,感觉freemarker还是不错的,虽然重用 + 灵活还是赶不上 PHP Template ,

呵呵

 

Well,强烈推荐大家使用Blueprint CSS啊!!!

 

拍砖吧。。。555

0
0
分享到:
评论
4 楼 番茄有益 2009-11-29  
不是拼Marco和JSP,可以把客户程序调用看看。
3 楼 key232323 2009-11-26  
各有所爱啦。。。没事就当逛逛好了

我可不强迫别人用freemarker。。
2 楼 蔡华江 2009-11-25  
嘿嘿,感觉这代码完全不能吸引我。
因为macro中内容过大,还不如使用jsp,那么可读性好,IDE支持好。
如果这个小的话,还真没话说,jsp还找不到重用性比得上的!
1 楼 key232323 2009-11-25  
还有一个比较让人吐血的一个macro集合,我就不贴出来了
1000行左右

结果增删改查的页面一个都不写了。。。(100table+)

相关推荐

    FreeMarker 写的一个分页macro(宏)测试

    在Java Web开发中,FreeMarker是一个非常常用的模板引擎,它允许开发者将业务逻辑与视图层分离,提高代码的可维护性和复用性。在这个"FreeMarker 写的一个分页macro(宏)测试"中,我们可以看到如何使用FreeMarker来...

    FreeMarker页面制作规范

    宏是FreeMarker中的一个重要特性,它允许开发者创建可重用的代码片段,这些代码片段可以像自定义指令一样在模板中被调用。宏可以包含任意的模板内容,包括变量、循环、条件判断等,这极大地增强了模板语言的功能性和...

    FreeMarker实例

    与JSP相比,FreeMarker更加专注于模板处理,不涉及Java代码,因此在复杂页面渲染和模板复用方面具有优势。 FreeMarker的工作原理是通过读取预先定义的模板文件,结合后台提供的数据模型,生成最终的输出文本。模板...

    FreeMarker文档.CHM

    理解并熟练掌握FreeMarker的这些功能,可以帮助开发者更高效地构建动态Web应用,实现清晰的代码分离,提升项目的可维护性和扩展性。通过阅读提供的“FreeMarker文档.CHM”,你可以深入学习每个特性,并找到解决具体...

    FreeMarker通用的分页

    FreeMarker中的宏允许我们封装可重用的代码块,这在实现通用分页时显得尤为重要。宏`genPagination`是为分页而创建的核心组件,其参数包括: - `url`:指定的URL,用于构建页面链接。 - `totalPages`:总页数。 - `...

    freemarker

    7. **模板继承(Template Inheritance)**:通过`&lt;#include&gt;`和`&lt;#macro&gt;`,你可以实现模板的复用和继承,提高代码的可维护性。 8. **宏(Macros)**:类似于函数,宏是可重用的代码片段,可以在多个地方调用。 9....

    freemarker入门代码

    - **模板继承**:使用`&lt;#assign&gt;`和`&lt;#include&gt;`,可以实现模板的继承和重用,提高代码复用性。 - **自定义指令**:通过实现`TemplateDirectiveModel`接口,可以扩展FreeMarker的功能,创建自定义的指令。 - **...

    FreeMarker

    10. **与其他技术的集成**:FreeMarker 能很好地与Spring框架、Struts框架等结合使用,提供Web应用的视图层解决方案。同时,它也可以与各种数据源(如数据库、XML文件)交互,获取数据。 综上所述,FreeMarker是一...

    struts2中使用freeMarker

    - FreeMarker支持模板继承,通过`&lt;#import&gt;`和`&lt;@macro&gt;`,可以创建可重用的片段和宏,提高代码的复用性。 - 主模板定义公共结构,子模板继承并覆盖特定部分。 8. **错误处理**: - 当FreeMarker模板存在错误时...

    FreeMarker_Programmer Guide

    `&lt;#macro&gt;`用于创建可重用的宏,类似函数。 **7. 自定义指令** FreeMarker允许开发人员定义自定义指令,扩展其功能。自定义指令通常以`&lt;@myDirective&gt;`的形式出现,可以处理更复杂的逻辑。 **8. 国际化(i18n)...

    apache-freemarker

    Apache FreeMarker是一个强大的模板引擎,它是Java编程语言的一个开源项目,主要用于生成动态内容,比如Web页面、电子邮件等。它的工作原理是将数据模型与HTML或者其他格式的模板结合,生成最终的输出。FreeMarker的...

    freemarker 教程 使用手册

    4. 宏:`#macro`定义可重用的代码块,类似于函数。`#call`用于调用宏。 5. 引入其他模板:`#include`和`#import`可以引入其他模板,实现代码复用。 三、Freemarker与Java集成 1. Servlet容器集成:在Servlet环境...

    freemarker.jar下载

    Freemarker模板语言是Freemarker的核心,它是一种声明式的语言,用于创建可重用的模板。FTL文件通常有`.ftl`扩展名,其中包含HTML或其他文本结构,以及变量和控制结构。例如,`&lt;#if&gt;`、`&lt;#foreach&gt;`、`&lt;#assign&gt;`等...

    FreeMarker-rumen.rar_freemarker

    FreeMarker是一款强大的、开源的模板引擎,主要...通过深入学习和熟练掌握FreeMarker,你可以更好地构建高效、可维护的Web应用。《FreeMarker入门.pdf》这本书应该会提供一个良好的起点,帮助你快速上手FreeMarker。

    freemarker与struts2详细配置

    - **宏定义**:使用`&lt;#macro&gt;`定义可重用的代码片段。 - **条件和循环**:FreeMarker支持`&lt;#if&gt;`、`&lt;#choose&gt;`、`&lt;#foreach&gt;`等控制结构。 通过这些配置和使用技巧,你可以高效地利用FreeMarker与Struts2进行Web...

    freemarker.zip

    Freemarker是一款强大的模板引擎,常用于Web应用中的视图层渲染,比如Java Web开发。它的设计目的是将数据模型和展现逻辑分离,让开发者可以专注于业务数据,而设计师则可以专注于页面布局。以下是对 Freemarker 的...

    FreeMarkerDemo1.zip

    在Java Web开发中,FreeMarker的作用是将后台处理的数据与预先设计好的模板结合,生成用户可见的页面。这使得开发者可以将业务逻辑与视图层分离,提高代码的可维护性和复用性。FreeMarker的模板语言(FTL)允许...

    freemarker入门文档

    Freemarker是一个强大的、开源的模板引擎,常用于Java应用中的视图层开发,尤其在Web应用程序中。它允许开发者使用简单的标记语言(通常称为Freemarker模板)来分离业务逻辑和显示逻辑,使得前端展示更加灵活且易于...

    freeMarker语法

    6. **宏(Macros)**: 宏类似于函数,可以定义和重用模板片段,通过 `#macro` 和 `#end` 定义。 **三、FreeMarker与Java集成** 1. **创建FreeMarker配置**: 首先需要创建一个`Configuration`对象,并设置模板路径...

    freemarker基础代码

    通过`&lt;#macro&gt;`定义,`&lt;@macro_name&gt;`调用,实现代码复用。 9. **国际化支持(Internationalization)**:FreeMarker支持i18n,可以方便地根据不同的语言环境输出对应的消息。 10. **模板继承与导入(Template ...

Global site tag (gtag.js) - Google Analytics