Java 无法分析日期:无法与Spring解析日期
我无法将数据从spring boot应用程序输入mysql数据库。 我抛出这个异常:Java 无法分析日期:无法与Spring解析日期,java,spring,date,parsing,illegalargumentexception,Java,Spring,Date,Parsing,Illegalargumentexception,我无法将数据从spring boot应用程序输入mysql数据库。 我抛出这个异常: Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'; nested exception is java.lang.Ill
Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "2018-06-17"]
在我的经典文章中,我做到了:
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private Date dataCreazione;
在类控制器中:
@RequestMapping(value="/aggiungi", method=RequestMethod.POST)
public String inserimentoarticolo(@RequestParam(value = "dataCreazione") Date date,
@ModelAttribute("newArticolo") Articolo a, @ModelAttribute("newCategoria") Categoria c,
@ModelAttribute("newIva") Iva i, BindingResult result,
HttpServletRequest request, HttpServletResponse response, Model model) throws ServletException, IOException {
c=categoriaService.selectById(Integer.parseInt(request.getParameter("categorie")));
i=ivaService.selectById(Integer.parseInt(request.getParameter("ive")));
a.setCodArticolo(Integer.parseInt(request.getParameter("codArticolo")));
a.setDescrizione(request.getParameter("descrizione"));
a.setDataCreazione(date);
a.setCategoria(c);
a.setIva(i);
articoloService.insArticolo(a);
return "index";
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat data = new SimpleDateFormat("dd-MM-yyyy");
data.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(data, false));
}
在jsp中:
<form:input id="dataCreazione" path="dataCreazione" type="date" pattern="dd/MM/yyyy" />
我做错了什么
多谢各位