给hexo博客添加后台系统(Nginx+tomcat+Springboot)
title: 给hexo博客添加后台系统(Nginx+tomcat+Springboot)
date: 2023/5/8
tags: 网站搭建
categories: 建站
1.需求
hexo只是个前端静态页面,一方面提交日志不方便,另一方面也没法拓展其他功能,
因此,萌生了一个开发基于springboot,甚至是基于springcloud的后台系统的想法。
2.架构
暂时先弄一个简单的springboot项目,(以后用springcloud,再集成区块链)
3.代码实现
1.云服务器上安装 Nginx,之前的博客已经安装过了2.部署 Spring Boot1.springboot 的controller层提供/hello的API接口
@PostMapping("/hello") @ResponseBody @CrossOrigin(origins = "http://101.42.229.55") public String hello(@RequestBody Map<String,String>requestBody) { System.out.println("step into hello..."); String input = requestBody.get("input"); String result = "Hello, " + input + "!"; return result; }
这个CrossOrigin注解是指定那些ip可以访问这个端口,相当于一个白名单
配置 Spring Boot 端口,默认是8080,我配置的是8081。这可以通过在 Spring Boot 的配置文件 application.properties 或 application.yml 中添加以下行来完成:
在springboot项目根据录下打包生成jar
然后会在target目录下生成web-app-1.0.jar
执行nohup java -jar $APP_NAME > start.log 2>&1 &启动springboot服务
nohup java -jar $APP_NAME > start.log 2>&1 &3.配置HEXO(Butterfly主题)
在hexo根目录下的新建/source/_date/widget.yml文件
top: - class_name: CLASSNAME id_name: IDNAME name: API调用 icon: fas fa-heartbeat html: '<!DOCTYPE html> <html> <head> <title>动态页面示例</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <h1>动态页面示例</h1> <input type="text" id="input" placeholder="请输入内容"> <button onclick="sendRequest()">提交</button> <p id="result"></p > <script> function sendRequest() { let input = document.getElementById("input").value; let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { document.getElementById("result").innerHTML = xhr.responseText; } }; xhr.open("POST", "http://101.42.229.55:8081/hello", true); xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify({input: input})); } </script> </body> </html> '
加了这个会在博客侧边栏中添加一个这个
xhr.open("POST", "http://101.42.229.55:8081/hello", true);
这个代码在点击提交后,会把输入框里的值取出来通过post方式调用/hello API,然后调用Springboot的对应服务
这样就实现了博客调用后台springboot的API,可扩展性大大增强,可以搞事情了!
相关知识
Hexo添加樱花动态效果背景
好物推荐:六款让人眼前一亮的个人博客
写好一篇博客文章
hexo换主题乱码问题的解决
如何修改hexo中主题的css
计算机毕业设计之 [含实训报告+源码等]javaweb花店管理系统[包运行成功]
搭建自己的个人博客(保姆级教程),服务器、域名、网站全篇
Vue.js 增删查改库存管理系统教程:新手友好的完整代码与详细步骤」 「从零开始的库存管理系统:Vue.js 实现搜索、编辑、删除与数据更新」 「超详细的 Vue.js CRUD 教程:带你一步步构
吴俊源/鲜花订购与管理系统
java毕业设计鲜花管理系统的设计与实现(springboot+mysql+jdk1.8+meven)
网址: 给hexo博客添加后台系统(Nginx+tomcat+Springboot) https://www.huajiangbk.com/newsview949087.html
上一篇: 一分钱不用花,一分钟搭建一个微官 |
下一篇: 鲜花管理系统(javaweb)资 |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039