1. //前端html
  1. <!DOCTYPE html>
    <html lang="en">
  2.  
  3. <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../static-recourse/css/home.css" />
    <link rel="stylesheet" href="../static-recourse/layui/layui.css" />
    <link rel="stylesheet" href="../static-recourse/css/guide.css"/>
    <script src="../static-recourse/js/jquery.min.js"></script>
    <title>网站首页</title>
    <style>
    .query .notFount {
    display: none;
    }
  4.  
  5. .unitList p a {
    margin-bottom: -4px;
    }
  6.  
  7. .unitList ul li {
    margin-left: 32px;
    margin-right: 4px;
    }
  8.  
  9. .unitList li p {
    margin: 12px auto;
    }
  10.  
  11. .unitInform .unitInf,
    .unitInform .printInf {
    margin-left: 50px;
    }
  12.  
  13. .unitInform .unitInf p {
    margin-top: 18px;
    font-size: 12px;
    }
  14.  
  15. .unitInform h3 {
    margin-top: 30px;
    }
  16.  
  17. .unitInform .printList p {
    margin-top: 20px;
    font-size: 12px;
    }
  18.  
  19. .unitInform input[type="button"] {
    margin-bottom: -6px;
    }
  20.  
  21. .unitInform {
    display: none;
    }
    .rules{
    width: 49%;
    float: left;
    }
    .standar{
    width: 49%;
    float: left;
    margin-left: 18px;
    }
    .leftspan{
    width: 49%;
    float: left;
    }
    </style>
    </head>
  22.  
  23. <body>
    <div class="content">
    <div class="content layui-row layui-col-space9">
    <div class="content_w serviceTable type_1_content rules">
    <span class="title">新闻资讯</span>
    <table class="layui-table service">
    <colgroup>
    <col width="250">
    <col width="50">
    <col>
    </colgroup>
    <!--<thead>
    <tr>
    <th>标题</th>
    <th>时间</th>
    </tr>
    </thead>-->
    <tbody id="guidance-list" class="guidance-list">
    <tr th:each="var,varStat : ${xwzxList}" th:if="${varStat.index} lt 5">
    <td class="titleTr">
    <span th:if="${var.isTop}"><img src="../static-recourse/img/pin_1.gif" style="padding-right: 5px;"/></span>
    <span th:if="${not var.isTop}"><img src="../static-recourse/img/folder_new.gif" style="padding-right: 5px;"/></span>
    <a th:utext="${var.title}" th:attr="data-id=${var.id},title=${var.title}">关于推进全国统一 “多证合一”改革的意见</a>
    </td>
    <td class="checkTr" th:text="${#dates.format(var.updateTime,'yyyy-MM-dd')}">2019-01-01</td>
    </tr>
    <tr th:each="i:${#numbers.sequence(1,5-xwzxList.size())}" th:if="${xwzxList.size()} lt 5">
    <td class="titleTr"><a>&nbsp;</a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    <tr>
    <td class="titleTr"><a href="new_guide.html?flag=0" target="_parent">更多>></a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    </tbody>
    </table>
    </div>
  24.  
  25. <div class="content_w serviceTable type_2_content standar">
    <span class="title">政策法规</span>
    <table class="layui-table service">
    <colgroup>
    <col width="250">
    <col width="50">
    <col>
    </colgroup>
    <!--<thead>
    <tr>
    <th>标题</th>
    <th>时间</th>
    </tr>
    </thead>-->
    <tbody id="guidance-list" class="guidance-list">
    <tr th:each="var,varStat : ${zcfgList}" th:if="${varStat.index} lt 5">
    <td class="titleTr">
    <span th:if="${var.isTop}"><img src="../static-recourse/img/pin_1.gif" style="padding-right: 5px;"/></span>
    <span th:if="${not var.isTop}"><img src="../static-recourse/img/folder_new.gif" style="padding-right: 5px;"/></span>
    <a th:utext="${var.title}" th:attr="data-id=${var.id},title=${var.title}">关于推进全国统一 “多证合一”改革的意见</a>
    </td>
    <td class="checkTr" th:text="${#dates.format(var.updateTime,'yyyy-MM-dd')}">2019-01-01</td>
    </tr>
    <tr th:each="i:${#numbers.sequence(1,5-zcfgList.size())}" th:if="${zcfgList.size()} lt 5">
    <td class="titleTr"><a>&nbsp;</a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    <tr>
    <td class="titleTr"><a href="new_guide.html?flag=1" target="_parent">更多>></a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    </tbody>
    </table>
    </div>
  26.  
  27. <div class="content_w serviceTable type_2_content leftspan">
    <span class="title">行业标准</span>
    <table class="layui-table service">
    <colgroup>
    <col width="250">
    <col width="50">
    <col>
    </colgroup>
    <!--<thead>
    <tr>
    <th>标题</th>
    <th>时间</th>
    </tr>
    </thead>-->
    <tbody id="guidance-list" class="guidance-list">
    <tr th:each="var,varStat : ${hybzList}" th:if="${varStat.index} lt 5">
    <td class="titleTr">
    <span th:if="${var.isTop}"><img src="../static-recourse/img/pin_1.gif" style="padding-right: 5px;"/></span>
    <span th:if="${not var.isTop}"><img src="../static-recourse/img/folder_new.gif" style="padding-right: 5px;"/></span>
    <a th:utext="${var.title}" th:attr="data-id=${var.id},title=${var.title}">关于推进全国统一 “多证合一”改革的意见</a>
    </td>
    <td class="checkTr" th:text="${#dates.format(var.updateTime,'yyyy-MM-dd')}">2019-01-01</td>
    </tr>
    <tr th:each="i:${#numbers.sequence(1,5-hybzList.size())}" th:if="${hybzList.size()} lt 5">
    <td class="titleTr"><a>&nbsp;</a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    <tr>
    <td class="titleTr"><a href="new_guide.html?flag=2" target="_parent">更多>></a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    </tbody>
    </table>
    </div>
  28.  
  29. <div class="content_w serviceTable type_2_content standar">
    <span class="title">知识园地</span>
    <table class="layui-table service">
    <colgroup>
    <col width="250">
    <col width="50">
    <col>
    </colgroup>
    <!--<thead>
    <tr>
    <th>标题</th>
    <th>时间</th>
    </tr>
    </thead>-->
    <tbody id="guidance-list" class="guidance-list">
    <tr th:each="var,varStat : ${zsydList}" th:if="${varStat.index} lt 5">
    <td class="titleTr">
    <span th:if="${var.isTop}"><img src="../static-recourse/img/pin_1.gif" style="padding-right: 5px;"/></span>
    <span th:if="${not var.isTop}"><img src="../static-recourse/img/folder_new.gif" style="padding-right: 5px;"/></span>
    <a th:utext="${var.title}" th:attr="data-id=${var.id},title=${var.title}">关于推进全国统一 “多证合一”改革的意见</a>
    </td>
    <td class="checkTr" th:text="${#dates.format(var.updateTime,'yyyy-MM-dd')}">2019-01-01</td>
    </tr>
    <tr th:each="i:${#numbers.sequence(1,5-zsydList.size())}" th:if="${zsydList.size()} lt 5">
    <td class="titleTr"><a>&nbsp;</a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    <tr>
    <td class="titleTr"><a href="new_guide.html?flag=3" target="_parent">更多>></a></td>
    <td class="checkTr">&nbsp;</td>
    </tr>
    </tbody>
    </table>
    </div>
    </div>
  30.  
  31. </div>
    </body>
    <script th:inline="javascript">
       // 后台数据传输到js变量中
       var down_url = [[${downUrl}]];
       var arry = [];
       arry = [[${FileList}]];
    // 查看每条记录
    $(".guidance-list").on('click', 'a', function () {
    var id = $(this).attr("data-id");
    if(id){
    window.open('details/'+id+'.html','_blank');// 详情跳转
    }
    })
    </script>
    </html>
  1. //END-前端html
  2.  
  3. //后端写操作
    package com.dhht.service;
  4.  
  5. import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Service;
    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.context.Context;
  6.  
  7. import javax.annotation.Resource;
    import java.io.File;
    import java.io.PrintWriter;
    import java.util.Map;
  8.  
  9. /**
    * @Author: sh
    * @Description: PageCacheService
    * @Date: 14:25 2019/9/24
    */
    @Slf4j
    @Service
    public class PageCacheService {
  10.  
  11. static String CACHE_FILE_SUFFIX = ".html";
  12.  
  13. @Value("${regulation_path}")
    String REGULATION_PATH;// 缓存页面磁盘路径
  14.  
  15. @Value("${regulation_temp_source}")
    String REGULATION_TEMP_SOURCE;
  16.  
  17. @Resource
    private TemplateEngine templateEngine;
  18.  
  19. /**
    * 模板数据填充
    *
    * @param valsMap
    * @param templateId
    */
    public void setValToTemplat(Map<String, Object> valsMap, String templateId) {
    setVals(valsMap,templateId,templateId,REGULATION_PATH);
    }
  20.  
  21. /**
    * 数据填充
    *
    * @param val 填充值
    * @param tempId 模板id
    * @param regulationId 资讯id
    * @param tarDir 本地磁盘目录
    */
    public void setVals(Map<String, Object> val, String tempId, String regulationId, String tarDir) {
    PrintWriter writer = null;
    try {
    Context context = new Context();
    context.setVariables(val);
    File dirPath = new File(tarDir);
    if (!dirPath.exists()) {
    dirPath.mkdirs();
    }
    File uploadFile = new File(tarDir, regulationId + CACHE_FILE_SUFFIX);// ResourceUtils.getFile("classpath:templates/" + templateId + ".html");
    if (uploadFile.exists()) {
    uploadFile.delete();
    }
    writer = new PrintWriter(uploadFile, "UTF-8");
    // 生成html,第一个参数是thymeleaf页面下的原型名称
    templateEngine.process(tempId, context, writer);
    } catch (Exception e) {
    log.error(e.getMessage());
    } finally {
    if(null!=writer){
    writer.close();
    }
    }
    }
    }
  1. package com.dhht.service;
  2.  
  3. import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Service;
    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.context.Context;
  4.  
  5. import javax.annotation.Resource;
    import java.io.File;
    import java.io.PrintWriter;
    import java.util.Map;
  6.  
  7. /**
    * @Author: sh
    * @Description: PageCacheService
    * @Date: 14:25 2019/9/24
    */
    @Slf4j
    @Service
    public class PageCacheService {
  8.  
  9. static String CACHE_FILE_SUFFIX = ".html";
  10.  
  11. @Value("${regulation_path}")
    String REGULATION_PATH;// 缓存页面磁盘路径
  12.  
  13. @Value("${regulation_temp_source}")
    String REGULATION_TEMP_SOURCE;
  14.  
  15. @Resource
    private TemplateEngine templateEngine;
  16.  
  17. /**
    * 模板数据填充
    *
    * @param valsMap
    * @param templateId
    */
    public void setValToTemplat(Map<String, Object> valsMap, String templateId) {
    setVals(valsMap,templateId,templateId,REGULATION_PATH);
    }
  18.  
  19. /**
    * 数据填充
    *
    * @param val 填充值
    * @param tempId 模板id
    * @param regulationId 资讯id
    * @param tarDir 本地磁盘目录
    */
    public void setVals(Map<String, Object> val, String tempId, String regulationId, String tarDir) {
    PrintWriter writer = null;
    try {
    Context context = new Context();
    context.setVariables(val);
    File dirPath = new File(tarDir);
    if (!dirPath.exists()) {
    dirPath.mkdirs();
    }
    File uploadFile = new File(tarDir, regulationId + CACHE_FILE_SUFFIX);// ResourceUtils.getFile("classpath:templates/" + templateId + ".html");
    if (uploadFile.exists()) {
    uploadFile.delete();
    }
    writer = new PrintWriter(uploadFile, "UTF-8");
    // 生成html,第一个参数是thymeleaf页面下的原型名称
    templateEngine.process(tempId, context, writer);
    } catch (Exception e) {
    log.error(e.getMessage());
    } finally {
    if(null!=writer){
    writer.close();
    }
    }
    }
    }

// 后台数据设置到js变量中var down_url = [[${downUrl}]];//"http://127.0.0.1:8080/downFile";var arry = [];arry = [[${FileList}]];

静态页面缓存(thymeleaf模板writer)的更多相关文章

  1. Spring Boot (4) 静态页面和Thymeleaf模板

    静态页面 spring boot项目只有src目录,没有webapp目录,会将静态访问(html/图片等)映射到其自动配置的静态目录,如下 /static /public /resources /ME ...

  2. 借助 Filter 生成静态页面缓存问题

    如果有些 jsp 页面,在一次 jsp 页面生成后 html 后, 就不太可能需要更新.可以使用缓存机制来解决这个问题. 解决思路如下 1.  定义一个文件夹 pagestaticize,用来存放 j ...

  3. 使用Varnish+ESI实现静态页面的局部缓存(思路篇)

    使用Varnish+ESI实现静态页面的局部缓存(思路篇) 页面静态化是搭建高性能网站必用的招式之一,页面静态化可以有效提升系统响应速度,同时也有利于搜索引擎优化.但在页面静态化后,静态页面之间包含( ...

  4. Nginx设置静态页面压缩和缓存过期时间的方法

    使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...

  5. Nginx设置静态页面压缩和缓存过期时间的方法 (转)

    使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...

  6. springboot-10-前端页面整合, thymeleaf, freemarker, jsp 模板使用

    springboot 中不建议使用jsp作为页面展示, 怎么使用可以看: http://412887952-qq-com.iteye.com/blog/2292471 关于什么是thymeleaf, ...

  7. 页面静态化3 --- 使用PHP页面缓存机制来完成页面静态化(下)操作一个案例(新闻管理系统)

    案例需求: 使用PHP缓存机制完成新闻管理系统的页面静态化数据库表 ecs_article (新闻表)因为新闻这些信息,并不是对实时性要求高,本身这个新闻比较稳定,内容也比较固定,所以我们考虑: 当第 ...

  8. (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用

    一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...

  9. SpringBoot入门篇--使用Thymeleaf模板引擎进行页面的渲染

    在做WEB开发的时候,我们不可避免的就是在前端页面之间进行跳转,中间进行数据的查询等等操作.我们在使用SpringBoot之前包括我在内其实大部分都是用的是JSP页面,可以说使用的已经很熟悉.但是我们 ...

随机推荐

  1. JavaWeb学习——了解HTML

    JavaWeb学习——了解HTML 摘要:本文主要简单介绍了什么是HTML以及如何使用. 定义 是什么 HTML(Hyper Text Markup Language),指的是超文本标记语言. 超文本 ...

  2. 第二阶段scrum-4

    1.整个团队的任务量: 2.任务看板: 会议照片: 产品状态: 前端制作完成,数据库在制作中.

  3. servlet 之 GenericServlet抽象类详解

    GenericSerlvet抽象类源码如下: package javax.servlet; import java.io.IOException; import java.util.Enumerati ...

  4. C#获取图片的某个区域

            /// <summary>        /// http://www.cnblogs.com/KissKnife/archive/2007/10/13/923352.ht ...

  5. leetcode 正则表达式 (动态规划)

    给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符'*' 匹配零个或多个前面的那一个元素所谓匹配,是要涵盖 整个 字符串 s的 ...

  6. check Linux文件夹个数

    (ls -l|grep "^-"| wc -l)查看某个文件夹下文件的个数.(ls -lR|grep "^-"| wc -l)查看某个文件夹下文件的个数,包括子 ...

  7. 吴裕雄--天生自然TensorFlow2教程:填充与复制

    import tensorflow as tf a = tf.reshape(tf.range(9), [3, 3]) a tf.pad(a, [[0, 0], [0, 0]]) tf.pad(a, ...

  8. PAT Advanced 1030 Travel Plan (30) [Dijkstra算法 + DFS,最短路径,边权]

    题目 A traveler's map gives the distances between cities along the highways, together with the cost of ...

  9. HTTP协议(一):概述

    背景介绍 但凡世界上牛逼的人物,都会有一个非常离奇的经历.比如说乞丐出身的皇帝朱元璋,出生时家中红光大作,映红了半边天;再比如说无良皇帝刘邦,简直不要太牛逼,说自己是老妈和一条白龙交合生出的自己,而老 ...

  10. 洛谷 P2658 汽车拉力比赛

    题目传送门 解题思路: 二分答案,然后bfs验证,如果从一个路标可以达到其它所有路标,则答案可行.知道找到最佳答案. AC代码: #include<iostream> #include&l ...