A.JSP
<form action="${pageContext.request.contextPath}/admin/publish/date/post/${post.postId}">
<input type="date" name="pDate">
<button type="submit">Submit</button>
</form>
控制器
@RequestMapping(value="/publish/date/post/{postId}")
public ModelAndView setPublishDatePostP(@PathVariable Integer postId,
@RequestParam("pDate") Date topublishDate,
BindingResult result,
HttpServletRequest request,
HttpServletResponse response,
HttpSession session) {
ModelAndView mView = new ModelAndView("test");
Date d = pDate;
mView.addObject("d", d);
return mView;
}
显示错误
任何人都知道如何将日期从Jsp传递给控制器?
答案 0 :(得分:0)
尝试此操作,在控制器中添加自定义日期格式化程序。
@InitBinder
public void intDate(WebDataBinder dataBinder){
dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
}
@PostMapping("/test")
public String test(@RequestParam("date") Date date) {
return date.toString();
}