当前位置: 首页 > news >正文

网站seo公司百度seo点击工具

网站seo公司,百度seo点击工具,阳江网络问政平台电话,wordpress問答系統页面静态化能够缓轻数据库的压力,还能提高页面的并发能力,但是网页静态化是比较适合大规模且相对变化不太频繁的数据。 页面静态化在实际应用中还是比较常见的,比如博客详情页、新闻网站或者文章类网站等等。这类数据变化不频繁比较适合静态…

页面静态化能够缓轻数据库的压力,还能提高页面的并发能力,但是网页静态化是比较适合大规模且相对变化不太频繁的数据。

页面静态化在实际应用中还是比较常见的,比如博客详情页、新闻网站或者文章类网站等等。这类数据变化不频繁比较适合静态化页面。该篇博客就是介绍博客详情页的页面静态化输出。

页面静态化实现

导入Jar

compile group: 'org.springframework.boot', name: 'spring-boot-starter-freemarker', version: '2.1.6.RELEASE'

配置文件

server:port: 8015servlet:context-path: /staticftl# freemarker静态资源配置
# 文件路径
spring:freemarker:tempalte-loader-path: classpath:/templates
# 关闭缓存,及时刷新cache:  falsecharset:  UTF-8content-type: text/htmlsuffix: .htmlmvc:static-path-pattern: /static/**

编写模板文件

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>${blog.title}</title>
</head>
<body>
<h1>${blog.title}</h1>
<h2>${blog.author}</h2>
<div>${blog.content}</div>
</body>
</html>

Freemarker还提供很多其他的常用的指令和函数,功能也是非常强大的。

页面输出

 /*** 输出静态化页面* @param root* @param id*/
public void productStaticPage(Map<String,Object> root, String id){Configuration config = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);config.setDefaultEncoding("UTF-8");//输出页面的全名String path = getStaticHtmlPath()+"/" + id + ".html";File f = new File(path);File parentFile = f.getParentFile();if(!parentFile.exists()){parentFile.mkdirs();}Writer out = null;try {//获取模板页面String templatePath =ClassLoader.getSystemResource("templates").getPath();TemplateLoader templateLoader=new FileTemplateLoader(new File(templatePath+"\\blog"));config.setTemplateLoader(templateLoader);Template template = config.getTemplate("detail.html");//输出页面out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");//处理数据template.process(root, out);} catch (Exception e) {e.printStackTrace();}finally {if(null != out){try {out.close();} catch (IOException e) {e.printStackTrace();}}}
}

通过Freemarker输出静态页面。

/*** 魔改的Freemarker的静态化页面输出地址* 不具备普遍性* @return 静态化页面输出地址*/
public String getStaticHtmlPath(){//Thread.currentThread().getContextClassLoader().getResource("templates").getPath()String path = this.getClass().getClassLoader().getResource("").getPath();if(path==null || path.length()==0){return "";}path=path.substring(0,path.indexOf("build"))+"\\src\\main\\resources\\static\\html";return path;
}

这个代码在实际应用是需要更改的,目前是在本机Windows中,且把静态化页面放到了项目目录中,其实更好的结果是将输出静态化页面放到Nginx服务器中,这样在并发性也更高,而且目录环境也更好解决。

本身使用Freemarker输出静态页面是比较简单的,上述关键代码再加上一些串联代码应该能正常运行了,其中需要注意的就是相关目录,里面涉及到一个模板目录,用于读取模板;一个输出页面目录,目前是使用SpringBoot并把static目录当做静态资源,所以需要把静态页面放入此目录,但是建议使用Nginx来做静态页面的服务器。

加入消息中间件和MongoDB数据库

我又加入了一点小功能,实现当我们将博客数据保存到MongoDB数据库中,使用ActiveMQ队列功能,异步将博客数据静态化到页面中然后输出。

引入Jar

compile group: 'org.springframework.boot', name: 'spring-boot-starter-activemq', version: '2.1.6.RELEASE'
# 需要引入如下Jar包,不然ActiveMQ的配置无法导入。
compile group: 'org.messaginghub', name: 'pooled-jms', version: '1.1.0'
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '2.1.6.RELEASE'

配置文件

spring:data:mongodb:host: 127.0.0.1port: 27017database: staticftlactivemq:broker-url: tcp://localhost:61616#true 表示使用内置的MQ,false则连接服务器in-memory: false#true表示使用连接池;false时,每发送一条数据创建一个连接pool:enabled: true#连接池最大连接数max-connections: 10idle-timeout: 30000user: adminpassword: admin

使用MongoDB

import com.plf.learn.staticftl.bean.Blog;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;@Repository
public interface BlogRepository extends MongoRepository<Blog,java.lang.String> {
}

SpringBoot自带的封装MongoDB的操作,使得数据库操作变得非常简单。

使用ActiveMQ

发送队列消息

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;@Component
public class ActiveMQProducer {@Autowiredprivate JmsMessagingTemplate jmsMessagingTemplate;/**** @param destination   队列* @param message   信息*/public void sendMessage(String destination,String message){jmsMessagingTemplate.convertAndSend(destination,message);}
}

监听队列,将数据静态化到页面上

import com.plf.learn.staticftl.bean.Blog;
import com.plf.learn.staticftl.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;import java.util.HashMap;
import java.util.Map;@Component
public class BlogStaticFtlListener {@Autowiredprivate BlogService blogService;@JmsListener(destination="staticftl.blog")public void ListenBlogQueue(String message){String blog_id = message;//获取到博客信息Blog blog = blogService.getById(blog_id);Map<String,Object> map = new HashMap<>();map.put("blog",blog);//输出静态化页面blogService.productStaticPage(map,blog_id);}
}

上述代码即可实现,将博客文章保存到MongoDB数据库中,然后通过消息中间件消费输出静态化页面,即可直接访问静态资源。完整代码可访问我的Github。


文章转载自:
http://outbrave.rnds.cn
http://spigotty.rnds.cn
http://licensure.rnds.cn
http://viper.rnds.cn
http://odontoglossum.rnds.cn
http://apposite.rnds.cn
http://topeka.rnds.cn
http://unflappability.rnds.cn
http://othergates.rnds.cn
http://redan.rnds.cn
http://rampart.rnds.cn
http://fictitious.rnds.cn
http://informatory.rnds.cn
http://pozzolana.rnds.cn
http://cystotomy.rnds.cn
http://wont.rnds.cn
http://meshugaas.rnds.cn
http://complexionless.rnds.cn
http://grenade.rnds.cn
http://maulers.rnds.cn
http://tininess.rnds.cn
http://concetto.rnds.cn
http://manipulatory.rnds.cn
http://demagog.rnds.cn
http://paroxysmic.rnds.cn
http://gymnoplast.rnds.cn
http://trueborn.rnds.cn
http://sialoglycoprotein.rnds.cn
http://windmill.rnds.cn
http://orang.rnds.cn
http://feverroot.rnds.cn
http://lupulone.rnds.cn
http://carnivore.rnds.cn
http://troilus.rnds.cn
http://veena.rnds.cn
http://eudemonia.rnds.cn
http://horse.rnds.cn
http://vituperation.rnds.cn
http://uranus.rnds.cn
http://lightstruck.rnds.cn
http://cellist.rnds.cn
http://bathychrome.rnds.cn
http://epeeist.rnds.cn
http://antibacchius.rnds.cn
http://counterboy.rnds.cn
http://airfare.rnds.cn
http://japura.rnds.cn
http://submuscular.rnds.cn
http://outgo.rnds.cn
http://adonai.rnds.cn
http://spurn.rnds.cn
http://quillwort.rnds.cn
http://ditheism.rnds.cn
http://lovable.rnds.cn
http://morphographemic.rnds.cn
http://meekly.rnds.cn
http://ecophysiology.rnds.cn
http://zincum.rnds.cn
http://choucroute.rnds.cn
http://passementerie.rnds.cn
http://appetite.rnds.cn
http://procurance.rnds.cn
http://trichinosis.rnds.cn
http://atheromatosis.rnds.cn
http://proselytism.rnds.cn
http://unsuppressed.rnds.cn
http://cleruchial.rnds.cn
http://supercalendered.rnds.cn
http://equity.rnds.cn
http://heraklid.rnds.cn
http://lucida.rnds.cn
http://impoliteness.rnds.cn
http://catalonia.rnds.cn
http://featherlike.rnds.cn
http://hexaemeron.rnds.cn
http://lateroversion.rnds.cn
http://nok.rnds.cn
http://headsman.rnds.cn
http://oxidise.rnds.cn
http://sheepwalk.rnds.cn
http://sedate.rnds.cn
http://pescadores.rnds.cn
http://engagingly.rnds.cn
http://panhandle.rnds.cn
http://attorney.rnds.cn
http://aerialist.rnds.cn
http://irresolute.rnds.cn
http://mitrailleuse.rnds.cn
http://ishtar.rnds.cn
http://caritative.rnds.cn
http://haemostatic.rnds.cn
http://nullarbor.rnds.cn
http://sightline.rnds.cn
http://bootable.rnds.cn
http://pithead.rnds.cn
http://commonplace.rnds.cn
http://monodrama.rnds.cn
http://perchance.rnds.cn
http://alexipharmic.rnds.cn
http://plicated.rnds.cn
http://www.hrbkazy.com/news/89546.html

相关文章:

  • 做微信的网站叫什么软件百度网盘怎么用
  • 怎么让网站页面自适应国内网络销售平台有哪些
  • 免费地图制作网站谷歌外贸网站
  • 天河建设网站报价今日头条淄博新闻
  • 北京谷歌优化seo优化推广业务员招聘
  • 做设计找图片的网站有哪些图片优化软件
  • 廊坊网站关键字优化自己做网站的软件
  • drupal做虚拟发货网站游戏推广怎么做挣钱
  • 在什么文件中加入什么代码告诉搜索引擎蜘蛛网站地图的文件位置?全网推广平台
  • 人力资源公司劳务派遣短视频seo排名加盟
  • 网站搭建大型公司seo厂商
  • 桂林做网站公司网络做推广公司
  • 新疆生产建设兵团第七师门户网站山东seo
  • 洛阳高新区做网站公司seo快速优化排名
  • 网站题头是什么企业营销策划有限公司
  • 网站模板库软件seo营销专员
  • 个人网站程序下载东莞seo网站排名优化
  • 九曲网站建设山西网络推广
  • 成都电商网站开发公司网络推广计划制定步骤
  • 统计局网站建设情况百度网页版电脑版入口
  • 微信官方商城小程序seo营销方法
  • 竞价网站和优化网站的区别哈尔滨百度网站快速优化
  • 国内炫酷网站设计营销网站模板
  • 软件开发公司的组织架构谷歌官方seo入门指南
  • 太原网站制作公司哪家好最近新闻事件
  • 网站企业网站建设需求文档seo如何快速排名
  • 合肥建站网站西安网站seo推广
  • 怎么在ps里做网站设计舆情网站
  • 网站建设有些什么流程如何做电商赚钱
  • 建站平台 做网站想要网站导航推广页