原文
模板 + 数据 = 输出
假设你需要一个网站上的HTML页面,与此类似:
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Welcome John Doe!</h1>
<p>Our latest product:
<a href="products/greenmouse.html">green mouse</a>!
</body>
</html>
但是用户的名字取决于登录的用户是谁,并且最新的产品信息应该来自于数据库.因为数据是动态的,所以你不能使用静态的HTML.相反,您可以使用期望输出的模板.模板与静态HTML将是相同的,除了它包含一些使FreeMarker动态的指令:
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Welcome ${user}!</h1>
<p>Our latest product:
<a href="${latestProduct.url}">${latestProduct.name}</a>!
</body>
</html>