获取后台数据并拼写HTML模板

来源:互联网 发布:科比10总决赛数据 编辑:程序博客网 时间:2024/05/22 04:44

模板下载地址:http://download.csdn.net/download/tikaber/10154297

/** *  * html模板 *  * */public Map<String, Object> templateHtml(Info info) {Map<String, Object> uploadURL = new HashMap<>();String fileame ="";try {String title = info.getTitle();String comefrom = info.getComefrom();String content = info.getContent();// 模板路径String filePath = Thread.currentThread().getContextClassLoader().getResource("templates/info_template.html").getPath();//String pathBack = Thread.currentThread().getContextClassLoader().getResource("templates").getPath();log.info(filePath);String templateContent = "";// 读取模板文件FileInputStream fileinputstream = new FileInputStream(filePath);int lenght = fileinputstream.available();byte bytes[] = new byte[lenght];fileinputstream.read(bytes);fileinputstream.close();templateContent = new String(bytes);log.info(templateContent);// 替换掉模板中相应的地方templateContent = templateContent.replaceAll("###title###", title);templateContent = templateContent.replaceAll("###comefrom###", comefrom);templateContent = templateContent.replaceAll("###content###", content);log.info(templateContent);// 根据时间得文件名Calendar calendar = Calendar.getInstance();fileame = String.valueOf(calendar.getTimeInMillis()) + ".html";// 生成的html文件保存路径。fileame = "/" + fileame;// 建立文件输出流FileOutputStream fileoutputstream = new FileOutputStream(fileame);log.info("文件输出路径:");log.info(fileame);byte tag_bytes[] = templateContent.getBytes();fileoutputstream.write(tag_bytes);fileoutputstream.close();} catch (Exception e) {log.info(e.toString());}if (!StringUtils.isEmpty(fileame)) {uploadURL.put("url", fileame);}return uploadURL;}


原创粉丝点击