开发者

Defining POJO id in Spring form for single object

开发者 https://www.devze.com 2023-04-06 20:20 出处:网络
this is what controller sends to me: model.addAttribute(\"weather\", weatherService.getWeatherByCity(id));

this is what controller sends to me:

model.addAttribute("weather", weatherService.getWeatherByCity(id));

this is my JSP:

<form:form commandName="newWeather" method="post" action="edit">
    <c:forEach items="${cities}" var="city">
        <form:input path="temperature"></form:input>
        <input type="submit" value="Submit">
    </c:forEach>
</form:form>

Problem:

I get one object from database named weather. I want to edit that by changing temperature. So I must send back atleast id and field temperature. I know how to 开发者_开发问答send back temperature as shown, but how can I send back my id.

I think I can get it from model by ${weather.id}, but how can I place it in form?


<input type="hidden" name="id" value="${weather.id}">
0

精彩评论

暂无评论...
验证码 换一张
取 消