我是靠谱客的博主 虚心乌冬面,最近开发中收集的这篇文章主要介绍org.springframework.validation.BindException问题解决,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'user' on field 'hiredate': rejected value [20150511]; codes [typeMismatch.user.hiredate,typeMismatch.hiredate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.hiredate,hiredate]; arguments []; default message [hiredate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'hiredate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'hiredate': no matching editors or conversion strategy found]
今天项目中用到了springmvc,前台有个输入框hiredate,传到后台User模型中的 (Date) hiredate中,并且写@InitBinder的自定义转换器
// 自定义类型转换器 @InitBinder public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { System.out.println("initBinder &&&&"+request.getParameter("hiredate")+"***"+request.getParameter("username")); binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyyMMdd"), true)); }
可是还是一直报错。各种调查后发现Data.class的类竟然导入的是Java.sql.Data包中的。 后修正为java.util.Data.
最后
以上就是虚心乌冬面为你收集整理的org.springframework.validation.BindException问题解决的全部内容,希望文章能够帮你解决org.springframework.validation.BindException问题解决所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复