简体   繁体   中英

Defining POJO id in Spring form for single object

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}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM