您的位置:首页 > 编程语言 > Java开发

springMVC 含时间类型的数据处理 405 错误

2016-07-08 21:16 495 查看
前端出现 

405 request method post not supported 

控制台出现

org.springframework.web.servlet.PageNotFound  - Request method 'POST' not supported

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







解决办法:

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

SimpleDateFormat 根据实际情况来写
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: