提交Spring表单时无法命中控制器

时间:2018-07-26 08:31:38

标签: java spring

我正在使用Spring 4.2.0和hibernate。我正在尝试向我的控制器提交包含日期字段的jsp spring表单。但是我无法击中控制器,这将引发以下异常:

Field error in object 'loginDetails' on field 'dateOfBooking':
rejected value [2018-02-09]; codes
 [typeMismatch.loginDetails.dateOfBooking,typeMismatch.dateOfBooking,typeMismatch.java.util.Date,typeMismatch];
arguments
[org.springframework.context.support.DefaultMessageSourceResolvable:
codes [loginDetails.dateOfBooking,dateOfBooking]; arguments [];
default message [dateOfBooking]]; default message [Failed to convert
property value of type 'java.lang.String' to required type
'java.util.Date' for property 'dateOfBooking'; nested exception is
java.lang.IllegalStateException: Cannot convert value of type
[java.lang.String] to required type [java.util.Date] for property
'dateOfBooking': no matching editors or conversion strategy found].

下面是我的jsp代码,bean和控制器代码。

这是我用于表预订的bean,其中包含一个日期字段:

@DateTimeFormat(pattern="yyyy-MM-dd")
private Date dateOfBooking;

这是我的控制器代码,由于任何原因都没有变热:

@RequestMapping("/bookingTable")  
public ModelAndView bookingTable(@ModelAttribute("loginDetails") BookingTable bookingTable,HttpServletRequest request,ModelMap model) throws ParseException{
    HttpSession session = request.getSession();
    //Doing something here
    return new ModelAndView("bookingDetails");  
}

请帮助我。我一直在努力做到这一点。但是不能。

1 个答案:

答案 0 :(得分:1)