Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’
1.传入的参数用String型的:String sdate,String fdate,
2.在参数使用之前:String转日期型
@RequestMapping(method = RequestMethod.POST, value = “/add.do”)
public void add(String text,
String sdate,
String fdate,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
Notice notice = new Notice();
notice.setText(text);
//2.String转日期型
SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMdd”);
Date newsdate=sdf.parse(sdate);
Date newfdate=sdf.parse(fdate);
notice.setSdate(newsdate);
notice.setFdate(newfdate);
int id = noticeService.create(notice);
if (id <= 0) {
request.setAttribute("message", "添加失败!");
request.getRequestDispatcher("toAdd.html").forward(request, response);
} else {
request.getRequestDispatcher("toEdit.html?id=" + id).forward(request, response);
}
}