web开发中页面静态化的示例分析

发布时间:2022-03-24 10:52:10 作者:小新
来源:亿速云 阅读:169

这篇文章给大家分享的是有关web开发中页面静态化的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

  public void GenerathHtmlByString() throws IOException, TemplateException {

  //创建配置类

  Configuration configuration=new Configuration(Configuration.getVersion());

  //模版内容

  String templateString="<html>\n" +

  "<head>\n" +

  "    <meta charset="UTF-8">\n" +

  "    <title>FreemarkerTest1</title>\n" +

  "</head>\n" +

  "<body>\n" +

  "   老同志,你也不要拽,${song}!\n" +

  "   \n" +

  "</body>\n" +

  "</html>";

  //模版加载器

  StringTemplateLoader loader=new StringTemplateLoader();

  loader.putTemplate("template", templateString);

  configuration.setTemplateLoader(loader);

  //得到模版

  Template template=configuration.getTemplate("template", "UTF-8");

  ?

  //定义数据模型

  Map<String,Object> map=new HashMap<>();

  map.put("song", "你一个月的工资才二十来块");

  //静态化

  String content= FreeMarkerTemplateUtils.processTemplateIntoString(template, map);

  System.out.println("我们打印一下静态化的内容 :" + content);

  ?

  //转化为流

  InputStream inputStream= IOUtils.toInputStream(content);

  //输出文件

  FileOutputStream fileOutputStream=new FileOutputStream(new File("F:\\test2.html"));

  int copy= IOUtils.copy(inputStream, fileOutputStream);

  System.out.println(copy);//209

  }

感谢各位的阅读!关于“web开发中页面静态化的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. PHPWeb开发入门的示例分析
  2. JavaWEB开发的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

web

上一篇:Docker如何查看日志

下一篇:如何用vue3开发一个打砖块小游戏

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》