如果你想自己这样做,不使用任何外部库,我认为一个干净的方法是创建一个“template.html”文件与所有的静态内容,例如:
/p>
"http://www.w3.org/TR/html4/loose.dtd">
$title为任何动态内容放置一个像$ tag的标签,然后执行这样的操作:
File htmlTemplateFile = new File("path/template.html");
String htmlString = FileUtils.readFileToString(htmlTemplateFile);
String title = "New Page";
String body = "This is Body";
htmlString = htmlString.replace("$title", title);
htmlString = htmlString.replace("$body", body);
File newHtmlFile = new File("path/new.html");
FileUtils.writeStringToFile(newHtmlFile, htmlString);