Freemarker
为什么使用freemarker?
使我们的代码更加的简洁,抒写修改更加的方便。在开发大型项目时代码太长一时找不到重点。使用Freemarker将多余的代码分散出去
使用Freemarker首先要导入jar包
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.9</version>
</dependency>
下面是总结的一些常用的语法
具体来看代码
<!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">
<body>
<div id="rightSide">
<@g.top />
<@g.container>
<table cellpadding="0" cellspacing="0" width="100%" class="sTable">
<tbody>
<#list goodses as goods>
<tr style="color:<#if goods_index%2==0>red<#else>blue</#if>">
<td>${goods_index+1}</td>
<td>${goods.id}</td>
</tr>
</#list>
</tbody>
</table>
</@g.container>
</div>
</body>
</html>
下面是被调用的页面
<#macro top>
<!-- Top fixed navigation -->
<div class="topNav">
<div class="wrapper">
<div class="welcome"><a href="#" title=""><img src="/static/images/userPic.png" alt="" /></a><span>Howdy, Eugene!</span></div>
<div class="userNav">
<ul>
<li><a href="#" title=""><img src="/static/images/icons/topnav/profile.png" alt="" /><span>Profile</span></a></li>
<li><a href="#" title=""><img src="/static/images/icons/topnav/tasks.png" alt="" /><span>Tasks</span></a></li>
<li class="dd"><a title=""><img src="/static/images/icons/topnav/messages.png" alt="" /><span>Messages</span><span class="numberTop">8</span></a>
<ul class="userDropdown">
<li><a href="#" title="" class="sAdd">new message</a></li>
<li><a href="#" title="" class="sInbox">inbox</a></li>
<li><a href="#" title="" class="sOutbox">outbox</a></li>
<li><a href="#" title="" class="sTrash">trash</a></li>
</ul>
</li>
<li><a href="#" title=""><img src="/static/images/icons/topnav/settings.png" alt="" /><span>Settings</span></a></li>
<li><a href="login.html" title=""><img src="/static/images/icons/topnav/logout.png" alt="" /><span>退出</span></a></li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</#macro>
<#macro container>
<div class="wrapper">
<div class="widget">
<div class="title"><img src="/static/images/icons/dark/frames.png" alt="" class="titleIcon" /><h6>Usual static table</h6></div>
<#nested />
</div>
</div>
</#macro>
有个嵌套调用不是很清晰,下面为大家附上图片:
代码千万行,注释第一行。格式不规范,报错两行泪!~