2

spring mvc を使用して、デフォルトの場所 (IP に基づく) の天気を表示する Web サイトを作成したい、またはアドレスを入力した場合は、アドレスに基づいて更新したい。しかし、入力しても更新されないのはなぜですか? すべてのデータがクラスで更新されます。問題の原因とその修正方法は?

他に必要な場合は、コントローラーとjspファイルを含めます。この質問を更新します。

デモウェブサイト:http://156.17.231.132:8080/

コントローラ:

@Controller
public class HomeController
{
    Weather weather;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String listUsers(ModelMap model, HttpServletRequest req) {

        Language.getInstance().setLanguage(LanguageManager.getLanguage(new Locale(System.getProperty("user.language"))));
        Location location = LocationManager.getLocation(req);
        weather = WeatherManager.getWeather(location);

        model.addAttribute("location", location);
        model.addAttribute("weather", weather);
        model.addAttribute("destination", new Destination());

        return "index";
    }

    @RequestMapping(value = "/search", method = RequestMethod.POST)
    public String addUser(@ModelAttribute("destination") Destination destination,BindingResult result) {
        destination = DestinationManager.getDestination(destination.getAddress());
        weather = WeatherManager.getWeather(destination);
        return "redirect:/";
    }
}

そしてここにjspファイルがあります:また、なぜ私のifがここで機能しないのですか?

<!doctype html>
<%@ page session="false" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="core" %>

<html>
<head>
    <meta charset="utf-8">
    <title>Weatherr</title>

    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
    <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>

<body>

<div class="container">
    <div class="row">
        <div class="span8 offset2">
            <%--<h2>Getting current weather data</h2>--%>
            <%--<h2>http://api.openweathermap.org/data/2.5/weather?lat=51.1&lon=17.0333&lang=en</h2>--%>
            <%--<h2>Getting forecast data every 3 hours</h2>--%>
            <%--<h2>http://api.openweathermap.org/data/2.5/forecast?lat=51.1&lon=17.0333&lang=en</h2>--%>
            <%--<h2>Getting daily forecast weather data - Seaching 10 days forecast by geographic coordinats </h2>--%>
            <%--<h2>http://api.openweathermap.org/data/2.5/forecast/daily?lat=51.1&lon=17.0333&cnt=10&mode=json&lang=en</h2>--%>

            <core:if test="${empty destination}">
                <h2>${location.city}, ${location.countryName}</h2>
            </core:if>

            <core:if test="${not empty destination}">
                <h2>${destination.address}</h2>
            </core:if>

            <h3>${weather.dt}</h3>

            <h3><img src="http://openweathermap.org/img/w/${weather.weatherData.icon}.png"
                     style="float:left; margin:5px 5px 5px 5px; border:0" alt="weather" width="20%" height="20%"/>

                ${weather.weatherData.description}</br>

                Temp: ${weather.main.temp}&deg;C</br>

                Wind speed: ${weather.wind.speed} mps, direction ${weather.wind.deg}  </br>

                Wind gust: ${weather.wind.gust} mps</br>

                Cloudiness: ${weather.clouds}% </br>

                Atmospheric pressure: ${weather.main.pressure}hPa </br>

                Humidity: ${weather.main.humidity}%</h3>

            <form:form method="post" action="search" commandName="destination" class="form-horizontal">
            <div class="control-group">
                <div class="controls">
                    <form:input path="address"/>
                    <input type="submit" value="Search" class="btn"/>
                    </form:form>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
</html>
4

1 に答える 1