无法将[java.lang.String]类型的属性值转换为@DateTimeFormat(模式=“HH:mm”)所需的[java.util.Date]类型
我正在尝试验证Spring 4.3上使用JQuery Timepicker生成的@DateTimeFormat(pattern=“HH:mm”),当我将数据对象发送到控制器时出现问题,这会生成异常无法将[java.lang.String]类型的属性值转换为@DateTimeFormat(模式=“HH:mm”)所需的[java.util.Date]类型,java,spring,hibernate,spring-mvc,datetime-format,Java,Spring,Hibernate,Spring Mvc,Datetime Format,我正在尝试验证Spring 4.3上使用JQuery Timepicker生成的@DateTimeFormat(pattern=“HH:mm”),当我将数据对象发送到控制器时出现问题,这会生成异常 Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property schedule.shChildTime; nested exception is ja
Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property schedule.shChildTime; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "00:00"
数据库上的属性为:
sh_child_time time without time zone NOT NULL DEFAULT '00:00:00'::time without time zone
Hibernate逆向工程使类映射,我添加了符号,属性计划类是:
private boolean shHappen;
private char shStatus;
private short shOrder;
@DateTimeFormat(pattern = "HH:mm")
private Date shChildTime;
private int[][] shOrderMatrix;
控制器正在通过ModelAttribute接收计划对象:
@RequestMapping(value = "/schedules/new", method = RequestMethod.POST)
public String saveSchedule(@ModelAttribute("persistDto")Schedule schedule, BindingResult result,Model model,Locale locale,HttpServletRequest request) {}
表单对象是,th:object=“${persistDto}”,带有thymeleaf的输入是:
<input th:field="*{schedule.shChildTime}" type="text" class="form-control" id="inputShChildTime" th:placeholder="#{schedule.hour.real}"/>
示例数据格式:“2017-01-01 12:00:12”您的问题可能与以下链接中提到的相同: 也可以编写转换器。你可以通过下面的链接
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}