[code="java"]
也照着demo写了个StringToDateConverter implements Converter,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);
}
[/code]
@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. 这个异常