论坛首页 Java企业应用论坛

Spring3 Web MVC下的数据类型转换(第一篇)——《跟我学Spring3 Web MVC》抢先看

浏览 54507 次
该帖已经被评为精华帖
作者 正文
   发表时间:2012-11-29  

Failed to convert from type java.lang.String to type @org.codehaus.jackson.map.annotate.JsonSerialize java.util.Date for value '2012-11-27'; nested exception is java.lang.IllegalArgumentException]  

 

估计配置有问题, 可否把spring-mvc详细配置也发上来。 或者可以的话站内信我你的demo

0 请登录后投票
   发表时间:2012-11-29   最后修改:2012-11-29
[quote="jinnianshilongnian"]
Failed to convert from type java.lang.String to type @org.codehaus.jackson.map.annotate.JsonSerialize java.util.Date for value '2012-11-27'; nested exception is java.lang.IllegalArgumentException] 


估计配置有问题, 可否把spring-mvc详细配置也发上来。 或者可以的话站内信我你的demo



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
        default-autowire="byName">
  
 <!--使用注解方式  -->
 <!-- Configures the @Controller programming model 必须加上这个,不然可能无法请求controller-->
 <mvc:annotation-driven />
 <!--由于使用声明式事务,事务并且控制在service层,所以此处不再扫描service包下的注解类,以防spring中的声明式事务失效 -->
 <context:component-scan base-package="cn.myshop">
  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> 
 </context:component-scan>
 
 <mvc:view-controller path="/" view-name="home"/>
 <!--声明系统将使用spring mvc那个控制器,springMVC默认为:BeanNameUrlHandlerMapping,根据控制器的名字将控制器映射到URL -->
 <bean id="beanNameUrlMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

 <!--使用Spring MVC的注解功能,完成请求和注解POJO的映射,添加拦截器,类级别的处理器映射 -->
 <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
 
 <bean id="myWebBinding" class="cn.myshop.platform.common.util.MyWebBinding"/>
 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
     <!-- 自定义属性编辑器 -->
     <property name="webBindingInitializer" ref="myWebBinding">
      </property>
       <property name="messageConverters">
   <list>
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
   </list>
  </property>
 </bean>
 
 <!--声明springMVC默认的视图解析器-->
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/jsp/"></property>
  <property name="suffix" value=".jsp"></property>
 </bean>
 
 <!--后台显示页面  -->
 <mvc:view-controller path="/admin/main.do" view-name="admin/main"/>
</beans>

 



这个demo放在项目里面的,比较大,你看还需要不?
0 请登录后投票
   发表时间:2012-11-29  
你需要把 <mvc:annotation-driven />
而使用你自定义的
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics