2
我想向spring mvc控制器提交一個類型爲「date」的輸入。 不幸的是,我不斷收到許多錯誤。我是新的春天mvc,特別是形式提交,不是很清楚爲什麼我需要在表單中有「commandName」。在spring mvc應用程序中提交input type =「date」
我迄今爲止代碼:
backoffice.jsp:
<form:form method="POST" action="/getAllOnDate" commandName="date">
<table>
<td><form:label path="date">Date</form:label></td>
<td><form:input type="date" path="date"/></td>
<input type="submit" value="View all on date"/>
</table>
</form:form>
控制器:
@RequestMapping(value = "/backoffice", method = RequestMethod.GET)
public String backofficeHome(Model model) {
model.addAttribute("date", new Date());
return "backoffice";
}
@RequestMapping(value = "/getAllOnDate", method = RequestMethod.POST)
public String getAllReservationsForRestaurantOnDate(@ModelAttribute("date") Date date, Model model) {
LOG.info(date.toString());
return "anotherPage";
}
只使用RequestParam代替的ModelAttribute – Rajesh
@Rajesh我覺得 「查看API」 爲基礎的解決方案(JSTL +模型)請求 – LoganMzz