如果某個變量test為null,在ftl頁面中會報錯,需要寫${test?default("N/A")},加入默認就沒錯了,還有就是if_exists,exists,!(嘆號)等等。
在<#if test??></#if>可以防止報錯,不能寫test==null這是不對的,還可以test?exists這樣寫。
學學模板:common.ftl
<#macro html title>
<html>
<head>
<title>${title?html}</title>
</head>
<body>
<#nested/>
</body>
</html>
</#macro>
使用頁面:test.ftl
<#import "common.ftl" as tl>
<@tl.html title="標題">
這里寫body的內容
</@tl.html>
ExtJS教程-
Hibernate教程-
Struts2 教程-
Lucene教程