当前位置:编程学习 > JAVA >>

springmvc无法接收Date类型参数

先问一下springmvc3.2.2似乎没有org.springframework.web.servlet这个jar包,那web.xml该如何配置。我这里使用了org.springframework.web.servlet-3.1.1.RELEASE.jar,采用
<servlet-name>springmvc</servlet-name>
     <servlet-class>
            org.springframework.web.servlet.DispatcherServlet //这个类,但是没这个包就没这个类,求解3.2.2中该在怎么配置
        </servlet-class>
....
的配置。
记下来是时间问题:我按网上说的配置了自定义转换器

public class DateConverter implements WebBindingInitializer {

public void initBinder(WebDataBinder binder, WebRequest request) {
     System.out.println(".....");
 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
 CustomDateEditor dateEditor = new CustomDateEditor(df, true);  
 binder.registerCustomEditor(Date.class, dateEditor);      

}

spring.xml配置:
  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  <property name="webBindingInitializer">
    <bean class="com.eastred.util.DateConverter"/>
  </property>
</bean> 
但并没有效果,似乎转换器没有运行,直接报错
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'content' on field 'createTime': rejected value [2013-06-07 22:56:50]; codes [typeMismatch.content.createTime,typeMismatch.createTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [content.createTime,createTime]; arguments []; default message [createTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createTime'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'createTime': no matching editors or conversion strategy found]
Field error in object 'content' on field 'updateTime': rejected value [2013-06-07 22:56:51]; codes [typeMismatch.content.updateTime,typeMismatch.updateTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [content.updateTime,updateTime]; arguments []; default message [updateTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'updateTime'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'updateTime': no matching editors or conversion strategy found]
求大神们帮忙 springmvc 异常 --------------------编程问答-------------------- org.springframework.web.servlet-3.1.1.RELEASE.jar 这个包就是你要的那个包 只是多了点版本信息而已  你那我想知道 你完整的web.xml中spring mvc那块的配置 --------------------编程问答--------------------   
  <servlet>
    <servlet-name>springmvc</servlet-name>
     <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/hib-config.xml,/WEB-INF/config/springmvc-servlet.xml,/WEB-INF/config/config.hbn.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping> --------------------编程问答-------------------- 类型转换错误,找一下是在把哪个String类型的property转换成Date类型呢? --------------------编程问答-------------------- 楼上什么意思? --------------------编程问答-------------------- 哦是createTime属性
目测还是转换部分错了,应该写得有问题 --------------------编程问答-------------------- 一般三种方法,最简单的注解。但是需要依赖那个开原的日期工具包。二是写个通用的属性编辑器。三就是控制器里搞定。我只实验过前两种。第三种比较单一。不灵活 --------------------编程问答-------------------- 楼上有木有例子,求指导
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,