src/com/pure/freemarker/MakeFile.java
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package com.pure.freemarker;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import com.pure.domain.News;
import com.pure.sys.Constant;
import com.pure.util.PureUtil;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class MakeFile {
/**
* 生成新的html文件
*
* @param news
* @param templateParam
* @return
*/
public String make(News news, TemplateParam templateParam) {
Configuration cfg = new Configuration();
// 项目真实路径
String realPath = templateParam.getRealPath();
// 新闻模板路径
String templatePath = realPath + Constant.NEWSTEMPLATEPATH;
String cDateStr = "news/" + PureUtil.getDateFormatStr("yyyyMMdd");
String filePostfix = ".html";
// 静态新闻生成文件存放路径
String path = realPath + cDateStr;
String fileTimeName = PureUtil.getDateFormatStr("yyyyMMddhhmmss");
// 写到数据库地路径
String returnFileName = cDateStr + "/" + fileTimeName + filePostfix;
String fileName = "";
File newsDir = new File(path);
fileName = path + "/" + fileTimeName + filePostfix;
if (!newsDir.exists()) {
newsDir.mkdirs();
fileName = path + "/" + fileTimeName + filePostfix;
}
try {
cfg.setDirectoryForTemplateLoading(new File(templatePath));
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template newsTemplate = cfg.getTemplate(templateParam.getTemplateName());
newsTemplate.setEncoding("GBK");
Map root = new HashMap();
root.put("news", news);
Writer out = new OutputStreamWriter(new FileOutputStream(fileName));
try {
newsTemplate.process(root, out);
后面还有 51 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。