上一篇介绍文章
上一篇介绍文章
https://blog.csdn.net/weixin_45206218/article/details/127872136
代码仓库
代码仓库
https://gitee.com/stevezhaozps/daily-weather
由于本项目使用的是springdatajpa,所以不需要我们手动建表,只需要建数据库启动项目,会自动建表
CREATE DATABASE daily_weather;
这里提供数据库备份
/*Navicat Premium Data TransferSource Server : win11Source Server Type : MySQLSource Server Version : 50740 (5.7.40-log)Source Host : localhost:3306Source Schema : daily_weatherTarget Server Type : MySQLTarget Server Version : 50740 (5.7.40-log)File Encoding : 65001Date: 17/11/2022 15:03:50
*/SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
-- Table structure for user_info
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (`id` bigint(20) NOT NULL,`bir_time` datetime NULL DEFAULT NULL,`city` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,`create_time` datetime NULL DEFAULT NULL,`district_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,`nickname` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,`scq_time` datetime NULL DEFAULT NULL,`type` int(11) NULL DEFAULT NULL,`update_time` datetime NULL DEFAULT NULL,`wechat_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,PRIMARY KEY (`id`) USING BTREE
) ENGINE = MyISAM CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;SET FOREIGN_KEY_CHECKS = 1;
如何申请见上一篇文章
server:port: 43310
# 微信配置
tencent:wechat:appId: 微信申请appidappSecret: 微信申请appSecret# 模板消息集合templatelist:- type: 1templateId: 模板id- type: 2templateId: 模板id- type: 3templateId: 模板id
# 百度天气配置
baidu:server: https://api.map.baidu.comak: 百度申请的ak
# 天行数据
tianxin:server: http://api.tianapi.comkey: 天行数据的key
spring:mvc:pathmatch:matching-strategy: ant_path_matcherdatasource:type: com.zaxxer.hikari.HikariDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/daily_weather?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghaiusername: 数据库用户password: 数据库密码hikari:minimum-idle: 5# 空闲连接存活最大时间,默认600000(10分钟)idle-timeout: 180000# 连接池最大连接数,默认是10maximum-pool-size: 10# 此属性控制从池返回的连接的默认自动提交行为,默认值:trueauto-commit: true# 连接池名称pool-name: MyHikariCP# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟max-lifetime: 1800000# 数据库连接超时时间,默认30秒,即30000connection-timeout: 30000connection-test-query: SELECT 1jpa:show-sql: true # 默认false,在日志里显示执行的sql语句database: mysqldatabase-platform: org.hibernate.dialect.MySQL5Dialecthibernate:ddl-auto: update #指定为update,每次启动项目检测表结构有变化的时候会新增字段,表不存在时会 新建,如果指定create,则每次启动项目都会清空数据并删除表,再新建naming:#指定jpa的自动表生成策略,驼峰自动映射为下划线格式7implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl#physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
# 日志
#logging:
# config: classpath:logback-spring-dev.xml
统一结果封装
注意返回String类型需要特殊处理
package com.zhao.wechat.advice;import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhao.wechat.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;/*** 对前端响应结果统一封装*/
@Slf4j
@RestControllerAdvice(basePackages = {"com.zhao.wechat.rest"})
public class ApiResponseAdvice implements ResponseBodyAdvice
xftp 上传文件 + xshell
通过xftp上传到云服务器
xshell执行jar
切换到当前jar目录下
# 启动
java -jar daily-weather-1.0.0.jar >/dev/null 2&1 &
# 启动成功会出现log目录,cd到log目录下可查看项目运行日志,有无报错# 查看项目是否在运行
ps -ef | grep daily-weather-1.0.0.jar
# 可看到线程的pid
kill -9 pid号,可以杀死当前运行的项目
正常启动成功后,使用公网ip:端口/doc.html可以访问swagger页面
上一篇:有哪些关于「纹身」的美句?
下一篇: 星座。狮子座