SpringBoot开发案例之打造十万博文Web篇

作者:微信小助手

发布时间:2019-08-05T08:45:24

点击▲关注 “爪哇笔记”   给公众号标星置顶

更多精彩 第一时间直达

前言

通过 Python 爬取十万博文之后,最重要的是要让互联网用户访问到,那么如何做呢?

选型

从后台框架、前端模板、数据库连接池、缓存、代理服务、限流等组件多个维度选型。

  • 后台框架 SpringBoot2+、JPA

  • 前端框架 Vue

  • 模块框架 Thymeleaf

  • 数据库连接池 HikariCP

  • 缓存 Redis

  • 限流 Guava

  • 代理服务 Nginx

  • 文章编辑 Markdown

架构

博文

我们可以通过以下方式访问:

 
  1. https://blog.52itstyle.top/49.html

亦或是:

 
  1. https://blog.52itstyle.top/49.shtml

当然,如果你愿意你也可以显示为:

 
  1. https://blog.52itstyle.top/49.php

  2. https://blog.52itstyle.top/49.asp

  3. https://blog.52itstyle.top/49.jsp

只需要在后台配置对应的映射关系即可:

 
  1. /**

  2. * 博文

  3. */

  4. @RequestMapping("{id}.html")

  5. public String blog(@PathVariable("id") Long id, ModelMap model) {

  6. Blog blog = blogService.getById(id);

  7. model.addAttribute("blog",blog);

  8. return "article";

  9. }

由于数据库存储的是 markedown 格式的数据,前台我们通过 editormd 转为 html 代码显示,这里只展示部分代码:

 
  1. <script type='text/javascript' src='js/jquery.min.js'></script>

  2. <!--省略部分代码-->

  3. <script type='text/javascript' src="editor/editormd.min.js"></script>

  4. <!--省略部分代码-->

  5. <div id="article">

  6. <textarea th:text="${blog.content}" style="display:none;" placeholder="markdown语言">

  7. </textarea>

  8. </div>

  9. <!--省略部分代码-->