test2

来源:互联网 发布:欢乐动漫 知乎 编辑:程序博客网 时间:2024/05/24 03:19
/** * 处理模板,并返回字符串流 *  * @author l00195395 * @since 2013-8-15 * @param path * @param resource * @param bindItems  * @param resourceString * @return * @throws IOException */private String genTemplate(HttpServletResponse httpResponse, String path, Map<String, List<?>> resource, Map<String, Object> bindItems)throws IOException {InputStream resourceStream = null;InputStreamReader streamReader = null;try {resourceStream = this.getClass().getClassLoader().getResourceAsStream(path);streamReader = new InputStreamReader(resourceStream,EncodingUtil.UTF_8);String resourceString = FreeMarkerTemplateUtils.processTemplateIntoString(new Template("", streamReader,new Configuration(), EncodingUtil.UTF_8), bindItems);httpResponse.getWriter().write(resourceString);return resourceString;} catch (TemplateException e) {throw new CommonSystemException("Convert home page error.", e);} finally {StreamUtil.closeStreams(resourceStream, streamReader);}}








/*    */ package org.springframework.ui.freemarker;/*    */ /*    */ import freemarker.template.Template;/*    */ import freemarker.template.TemplateException;/*    */ import java.io.IOException;/*    */ import java.io.StringWriter;/*    */ /*    */ public abstract class FreeMarkerTemplateUtils/*    */ {/*    */   public static String processTemplateIntoString(Template template, Object model)/*    */     throws IOException, TemplateException/*    */   {/* 48 */     StringWriter result = new StringWriter();/* 49 */     template.process(model, result);/* 50 */     return result.toString();/*    */   }/*    */ }


0 0