问题描述
也照着demo写了个StringToDateConverter implements Converter<String, Date>,xml也跟着配置了,bean类如下public class SearchBookableRoom {@NotBlank(message="开始日期必须指定")@Future(message="不支持当前指定的开始时间")@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")private Date beginTime;@NotBlank(message="不能为空")private String pid; @Min(value=1,message="消费时长不能低于1小时")private String timeLength;controller类加了@InitBinder //此处的参数也可以是ServletRequestDataBinder类型public void initBinder(ServletRequestDataBinder binder) throws Exception {DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");CustomDateEditor dateEditor = new CustomDateEditor(df, true);binder.registerCustomEditor(Date.class, dateEditor);}@RequestMapping(value="bookable-search",method=RequestMethod.GET)public void SearchBookableRoom(@Valid SearchBookableRoom order,BindingResult bindingResult,HttpServletRequest request,HttpServletResponse response) throws IOException{但是没次都会抛出 HV000030: No validator could be found for type: java.util.Date. 这个异常
解决方案
1、No validator could be found for type: java.util.Date 意思是没有校验器 不是转换器 看看有没有添加hibernate validator jar包2、你使用了@DateTimeFormat(pattern="yyyy-MM-dd HH:mm") 就没必要自定义类型转换器 请添加joda 相关jar包即可3、更多可参考我的博客http://jinnianshilongnian.iteye.com/blog/1733708