基于 MybatisPlus 将百度天气数据存储至 PostgreSQL 的实践
前言
本文介绍如何使用 MybatisPlus 框架将百度天气 API 数据获取、解析并持久化存储至 PostgreSQL 数据库。通过 ORM 映射和便捷操作接口,实现天气数据的高效增删改查。
数据库设计与实现
模型设计
根据业务维度设计数据库模型,分别存储天气接口返回的数据:实时天气、警报信息、指数信息、预报信息及小时预报表。
物理表结构
存储实时天气信息:
create table biz_weather_now ( pk_id INT8 not null, location_code VARCHAR(6) not null default '', temp DECIMAL(8,2) not null default 999999, feels_like DECIMAL(8,2) not null default 999999, rh DECIMAL(8,2) not null default 999999, wind_class VARCHAR(10) null, wind_dir VARCHAR(10) null, text VARCHAR(50) null, prec_1h DECIMAL(8,2) null default 999999, clouds DECIMAL(8,2) null , vis (,) , aqi (,) , pm25 (,) , pm10 (,) , no2 (,) , so2 (,) , o3 (,) , co (,) , uptime , PK_BIZ_WEATHER_NOW (pk_id) ); comment biz_weather_now ; comment biz_weather_now.pk_id ; comment biz_weather_now.location_code ; comment biz_weather_now.temp ; comment biz_weather_now.feels_like ; comment biz_weather_now.rh ; comment biz_weather_now.wind_class ; comment biz_weather_now.wind_dir ; comment biz_weather_now.text ; comment biz_weather_now.prec_1h ; comment biz_weather_now.clouds ; comment biz_weather_now.vis ; comment biz_weather_now.aqi ; comment biz_weather_now.pm25 ; comment biz_weather_now.pm10 ; comment biz_weather_now.no2 ; comment biz_weather_now.so2 ; comment biz_weather_now.o3 ; comment biz_weather_now.co ; comment biz_weather_now.uptime ;


