From 924942f065659621cf7cc6b918af69abe1e189c7 Mon Sep 17 00:00:00 2001 From: wenfei Date: Mon, 16 Jun 2025 08:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E6=9C=8D=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weather/controller/WeatherController.java | 13 +++++++++++++ .../rehome/weather/dao/WeatherFutureRepository.java | 2 +- 20240922/weather/src/main/resources/application.yml | 6 +++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/20240922/weather/src/main/java/com/rehome/weather/controller/WeatherController.java b/20240922/weather/src/main/java/com/rehome/weather/controller/WeatherController.java index 683bd36..a6ca01e 100644 --- a/20240922/weather/src/main/java/com/rehome/weather/controller/WeatherController.java +++ b/20240922/weather/src/main/java/com/rehome/weather/controller/WeatherController.java @@ -74,4 +74,17 @@ public class WeatherController { public Map getLocalWeatherByCity(@RequestParam("city") String city){ return weatherService.getLocalWeatherByCity(city); } + /** + * @date 2021-04-29 11:45 + * @description: 根据城市查询天气数据,查本地数据库 + * @Param: null + */ + @CrossOrigin + @RequestMapping(value = "/getLocalWeather",method = RequestMethod.GET) + public Map getLocalWeather(){ + //惠阳 or 2220 + //惠州 or 2218 + String city = "惠阳"; + return weatherService.getLocalWeatherByCity(city); + } } diff --git a/20240922/weather/src/main/java/com/rehome/weather/dao/WeatherFutureRepository.java b/20240922/weather/src/main/java/com/rehome/weather/dao/WeatherFutureRepository.java index bed1f51..a523206 100644 --- a/20240922/weather/src/main/java/com/rehome/weather/dao/WeatherFutureRepository.java +++ b/20240922/weather/src/main/java/com/rehome/weather/dao/WeatherFutureRepository.java @@ -11,7 +11,7 @@ public interface WeatherFutureRepository extends JpaRepository findByDate(String date); - @Query(value = "select * from weather_future wf where wf.city = ?1 ORDER BY id DESC LIMIT 0,1", nativeQuery = true) + @Query(value = "select * from weather_future wf where wf.city = ?1 ORDER BY id DESC LIMIT 0,5", nativeQuery = true) Optional> findAllByCity(String city); } diff --git a/20240922/weather/src/main/resources/application.yml b/20240922/weather/src/main/resources/application.yml index 7e84fa3..3bdd688 100644 --- a/20240922/weather/src/main/resources/application.yml +++ b/20240922/weather/src/main/resources/application.yml @@ -1,13 +1,13 @@ server: - port: 28902 + port: 8080 spring: datasource: type: com.zaxxer.hikari.HikariDataSource #driverClassName: com.mysql.jdbc.Driver #com.mysql.cj.jdbc.Driver com.mysql.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver #com.mysql.cj.jdbc.Driver com.mysql.jdbc.Driver #url: jdbc:mysql://192.168.1.21:3306/weather?useUnicode=true&characterEncoding=utf-8&useSSL=false - #url: jdbc:mysql://127.0.0.1:3306/weather?useUnicode=true&characterEncoding=utf-8&useSSL=false - url: jdbc:mysql://192.168.1.24:3306/weather?useUnicode=true&characterEncoding=utf-8&useSSL=false + url: jdbc:mysql://127.0.0.1:3306/weather?useUnicode=true&characterEncoding=utf-8&useSSL=false + #url: jdbc:mysql://192.168.1.24:3306/weather?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: Skyinno251, jpa: