静态页面缓存(thymeleaf模板writer)
//前端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> </a></td>
<td class="checkTr"> </td>
</tr>
<tr>
<td class="titleTr"><a href="new_guide.html?flag=0" target="_parent">更多>></a></td>
<td class="checkTr"> </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> </a></td>
<td class="checkTr"> </td>
</tr>
<tr>
<td class="titleTr"><a href="new_guide.html?flag=1" target="_parent">更多>></a></td>
<td class="checkTr"> </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> </a></td>
<td class="checkTr"> </td>
</tr>
<tr>
<td class="titleTr"><a href="new_guide.html?flag=2" target="_parent">更多>></a></td>
<td class="checkTr"> </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> </a></td>
<td class="checkTr"> </td>
</tr>
<tr>
<td class="titleTr"><a href="new_guide.html?flag=3" target="_parent">更多>></a></td>
<td class="checkTr"> </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)的更多相关文章
- Spring Boot (4) 静态页面和Thymeleaf模板
静态页面 spring boot项目只有src目录,没有webapp目录,会将静态访问(html/图片等)映射到其自动配置的静态目录,如下 /static /public /resources /ME ...
- 借助 Filter 生成静态页面缓存问题
如果有些 jsp 页面,在一次 jsp 页面生成后 html 后, 就不太可能需要更新.可以使用缓存机制来解决这个问题. 解决思路如下 1. 定义一个文件夹 pagestaticize,用来存放 j ...
- 使用Varnish+ESI实现静态页面的局部缓存(思路篇)
使用Varnish+ESI实现静态页面的局部缓存(思路篇) 页面静态化是搭建高性能网站必用的招式之一,页面静态化可以有效提升系统响应速度,同时也有利于搜索引擎优化.但在页面静态化后,静态页面之间包含( ...
- Nginx设置静态页面压缩和缓存过期时间的方法
使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...
- Nginx设置静态页面压缩和缓存过期时间的方法 (转)
使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...
- springboot-10-前端页面整合, thymeleaf, freemarker, jsp 模板使用
springboot 中不建议使用jsp作为页面展示, 怎么使用可以看: http://412887952-qq-com.iteye.com/blog/2292471 关于什么是thymeleaf, ...
- 页面静态化3 --- 使用PHP页面缓存机制来完成页面静态化(下)操作一个案例(新闻管理系统)
案例需求: 使用PHP缓存机制完成新闻管理系统的页面静态化数据库表 ecs_article (新闻表)因为新闻这些信息,并不是对实时性要求高,本身这个新闻比较稳定,内容也比较固定,所以我们考虑: 当第 ...
- (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用
一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...
- SpringBoot入门篇--使用Thymeleaf模板引擎进行页面的渲染
在做WEB开发的时候,我们不可避免的就是在前端页面之间进行跳转,中间进行数据的查询等等操作.我们在使用SpringBoot之前包括我在内其实大部分都是用的是JSP页面,可以说使用的已经很熟悉.但是我们 ...
随机推荐
- Git详细命令
Git Guidegit的三种方式只在本地使用:将本地仓库上传到Github:下载GitHub上的仓库:1.只在本地使用在Git Bush上输入命令 mkdir git-demo-1 ——创建一个目录 ...
- pyinstaller打包PySide2写的GUI程序,调用ffmpeg隐藏CMD控制台解决方案
1 问题描述 使用PySide2写了一个GUI程序,调用ffmpeg命令行工具,做简单的批量视频处理(调整帧宽度.帧高度.视频变速.降低视频码率达到限制视频大小),使用了ffmpeg. ffmpeg- ...
- 112-PHP类变量之间的赋值标识为同一个对象(二)
<?php class mao{ //定义猫类 public $age=0; //定义多个属性并初始化 public $weight=50; public $color='white'; } $ ...
- 移动端触屏click点击事件延迟问题,以及tap的解决方案
在移动端 触屏click事件虽然也会响应,但是总感觉是有延迟,一直听说click事件在手机上有200~300毫秒的延迟问题,亲自测了一下,在pc端模拟手机的话是测不出来的,但是用手机测试时发现延迟非常 ...
- PostAsync与GetAsync
using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; u ...
- js基础学习之-js包装对象
var test = "test"; test.a = "hello"; console.log(test.a); //undifined 定义: 在JavaS ...
- mac安装和启动mongodb
使用使用 brew安装mongodb 可以使用 OSX 的 brew 来安装 mongodb: sudo brew install mongodb 如果要安装支持 TLS/SSL 命令如下: sudo ...
- POJ 1126:Simply Syntax
Simply Syntax Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5264 Accepted: 2337 Des ...
- c++ 字符串转数字或数字转字符串
在C++中字符串转换为数字,或数字转换为字符串,用到如下函数: _itoa atoi.atof.itoa.itow _itoa_s 1.整形转换为字符串: wchar_t * _itot(int _V ...
- javascript数组日期
arr forEach(callback,thisArg) thisArg:指明回调函数的this指向 callback(element,index,arr) element:每次取到的数组元素值 i ...
