springMVC form表单提交---包含时间类型的数据

xiaoxiao2021-02-28  7

当form表单中的数据是基本类型的时,直接请求action中的url,一点问题都没有。

但是当form表单总有时间类型的数据时,且对应的controller是用一个java对象来绑定对应form提交的数据时,就会出现问题。无法提交成功。

解决办法:

在对应的controller中新增下面的方法:

/**       * form表单提交 Date类型数据绑定       * <功能详细描述>       * @param binder       * @see [类、类#方法、类#成员]       */   @InitBinder     public void initBinder(WebDataBinder binder) {             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");             dateFormat.setLenient(false);             binder.registerCustomEditor(Date.classnew CustomDateEditor(dateFormat, true));     }  

转载请注明原文地址: https://www.6miu.com/read-1600383.html

最新回复(0)