是否可以通过使用select标签将对象(汽车)传递给我的控制器?当我尝试使用下面的代码,车子参数没有被认可,它的结果是:如何在控制器中将对象传递给ModelAttribute - Spring
400错误的请求
一个car
由2串(品牌,型号) 一个spot
由1号车和2个字符串(镇,streetName)
我的JSP页面:
<form:form method="post" modelAttribute="spot" action="${post_url}">
<form:select path="car">
<form:option value="-" label="--Select car"/>
<form:options items="${cars}"/>
</form:select>
<form:input type="text" path="town"/>
<form:input type="text" path="streetName"/>
<button>Save</button>
</form:form>
我对照奥勒:
@RequestMapping(value="/addSpot", method = RequestMethod.POST)
public String save(@ModelAttribute("spot") Spot spot){
service.addSpotToService(spot);
return "redirect:/spots.htm";
}
当我实现这一点,我得到一个错误,而加载JSP中bean类汽车的财产“车”是无效的。可能是因为中的路径设置为“car” –
denelias
Class Car是否有ID? –
是的,私人长ID – denelias