//前端html
<!DOCTYPE html>
<html lang="en"> <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;
} .unitList p a {
margin-bottom: -4px;
} .unitList ul li {
margin-left: 32px;
margin-right: 4px;
} .unitList li p {
margin: 12px auto;
} .unitInform .unitInf,
.unitInform .printInf {
margin-left: 50px;
} .unitInform .unitInf p {
margin-top: 18px;
font-size: 12px;
} .unitInform h3 {
margin-top: 30px;
} .unitInform .printList p {
margin-top: 20px;
font-size: 12px;
} .unitInform input[type="button"] {
margin-bottom: -6px;
} .unitInform {
display: none;
}
.rules{
width: 49%;
float: left;
}
.standar{
width: 49%;
float: left;
margin-left: 18px;
}
.leftspan{
width: 49%;
float: left;
}
</style>
</head> <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> <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> <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> <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> </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>
//END-前端html

//后端写操作
package com.dhht.service; 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; import javax.annotation.Resource;
import java.io.File;
import java.io.PrintWriter;
import java.util.Map; /**
* @Author: sh
* @Description: PageCacheService
* @Date: 14:25 2019/9/24
*/
@Slf4j
@Service
public class PageCacheService { static String CACHE_FILE_SUFFIX = ".html"; @Value("${regulation_path}")
String REGULATION_PATH;// 缓存页面磁盘路径 @Value("${regulation_temp_source}")
String REGULATION_TEMP_SOURCE; @Resource
private TemplateEngine templateEngine; /**
* 模板数据填充
*
* @param valsMap
* @param templateId
*/
public void setValToTemplat(Map<String, Object> valsMap, String templateId) {
setVals(valsMap,templateId,templateId,REGULATION_PATH);
} /**
* 数据填充
*
* @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();
}
}
}
}
package com.dhht.service;

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; import javax.annotation.Resource;
import java.io.File;
import java.io.PrintWriter;
import java.util.Map; /**
* @Author: sh
* @Description: PageCacheService
* @Date: 14:25 2019/9/24
*/
@Slf4j
@Service
public class PageCacheService { static String CACHE_FILE_SUFFIX = ".html"; @Value("${regulation_path}")
String REGULATION_PATH;// 缓存页面磁盘路径 @Value("${regulation_temp_source}")
String REGULATION_TEMP_SOURCE; @Resource
private TemplateEngine templateEngine; /**
* 模板数据填充
*
* @param valsMap
* @param templateId
*/
public void setValToTemplat(Map<String, Object> valsMap, String templateId) {
setVals(valsMap,templateId,templateId,REGULATION_PATH);
} /**
* 数据填充
*
* @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. 13.swoole学习笔记--DNS查询

    <?php //执行DNS查询 swoole_async_dns_lookup("www.baidu.com",function($host,$ip){ echo $ip; ...

  2. 一百、SAP中ALV事件之十三,给ALV的自定义按钮添加事件

    一.我们查看定义的按钮,有一个名字是ZADD的自定义按钮 二.代码如下,用于判断点击了哪个按钮 三.点击测试按钮之后,会弹出一个弹窗 完美

  3. Java中的日期表示类

    一.概述 Java中的日期类设计的比较失败,刚开始使用Date来计算时间,后来大部分Date类的方法都过时了:想用Calendar类代替Date类,然而Calendar类也是不尽如人意.下面简单介绍下 ...

  4. junit基础学习之-多线程测试(6)

    步骤: 1.定义单个TestRunner 2.重载单个TestRunner的runTest() 3.定义TestRunner数组,并添加多个TestRunner 4.MultiThreadedTest ...

  5. oracle问题:char类型数据查询不到

    select distinct id,name from test_table b where b.ID='001' ; id为char字段类型,使用该语句查询不出数据. 解决方法:加trim().改 ...

  6. vue 操作列的自定义

    <el-table-column label="操作"> <template slot-scope="scope"> // 用到了 el ...

  7. Django 数据库配置

    DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'books', #你的数据库名称 'USER': ' ...

  8. jar类库加载顺序

    当我们启动一个tomcat的服务的时候,jar包和claess文件加载顺序: 1. $java_home/lib 目录下的java核心api 2. $java_home/lib/ext 目录下的jav ...

  9. P 1025 链表反转

    转跳点:

  10. Codeforces 392 C Unfair Poll(模拟)

    题意:老师点名顺序规则如下:第1排,第2排,……,第n-1排,第n排,第n-1排,……,第2排,第1排,第2排,……,第n-1排,第n排,……对于每排都是从左到右依次点名,问点名k个人后,所有人中最多 ...