spring MVC 参数传递类型转换时出现 The request sent by the client was syntactically incorrect

The request sent by the client was syntactically incorrect

客户发送的请求在语法上是不正确的。


转换器

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


import org.springframework.core.convert.converter.Converter;
/** 
 * 将字符串转换成日期 
 *  
 * 需要实现Converter接口,这里是将String类型转换成Date类型 
 * @author Administrator 
 *  
 */  
public class StringToDateConverter implements Converter<String, Date> {  
  
    @Override  
    public Date convert(String arg0) {  
        // 日期格式  
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
  
        try {  
            return sdf.parse(arg0);  //解析  
        } catch (ParseException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        } 
  
        return null;  
    }  
  
}  

springmvc-xml配置

 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
       	http://www.springframework.org/schema/aop 
	  	http://www.springframework.org/schema/aop/spring-aop.xsd
	  	http://www.springframework.org/schema/tx
      	http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">


	<context:component-scan base-package="com.wxjp.controller" />




	<mvc:resources location="/WEB-INF/css/" mapping="/css/**"></mvc:resources>
	<mvc:resources location="/WEB-INF/js/" mapping="/js/**"></mvc:resources>


	<!-- 定义文件上传解析器 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 设定默认编码 -->
		<property name="defaultEncoding" value="UTF-8"></property>
		<!-- 设定文件上传的最大值5MB,5*1024*1024 -->
		<property name="maxUploadSize" value="5242880"></property>
	</bean>


	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>


	<!--5. 自定义参数 -->
	<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
		<!-- 转换器 -->
		<property name="converters">
			<list>
				<bean class="com.wxjp.util.StringToDateConverter" />  <!-- 自定义的日期 -->
			</list>
		</property>


	</bean>
	<!-- 指定自定义参数 -->
	<mvc:annotation-driven conversion-service="conversionService" />
	<mvc:annotation-driven />
</beans>


设置没问题,但是在设置springmvc-xml的转换器配置时前面有这样一句把他删了就好了

<mvc:annotation-driven />


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值