SpringMVC报错The request sent by the client was syntactically incorrect ()

springmvc数据绑定出的错

在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写,

如果不一致,可能回报如下错误: 

The request sent by the client was syntactically incorrect ().

从字面上理解是:客户端发送的请求语法错误。

实际就是springmvc无法实现数据绑定。 
查看一下你传的参数是不是有date类型等Springmvc不支持参数绑定的类型,需自己绑定

date时间类型绑定 String-->date

String--> date 时间格式

 1 package com.online.util;
 2 
 3 import java.text.ParseException;
 4 import java.text.SimpleDateFormat;
 5 import java.util.Date;
 6 import java.util.Locale;
 7 
 8 import org.springframework.format.Formatter;
 9 
10 public class DateFormatter implements Formatter<Date>{
11 
12     
13     public String print(Date object, Locale locale) {  
14         return null;  
15     }  
16   
17     public Date parse(String text, Locale locale) throws ParseException {  
18         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
19         Date date = null;  
20         try {  
21             date = format.parse(text);  
22         } catch (Exception e) {  
23             format = new SimpleDateFormat("yyyy-MM-dd");  
24             date = format.parse(text);  
25         }  
26         return date;  
27     }  
28 }

在Spring的applicationContext.xml中注入这个类

1 <!-- 时间类型转换 -->
2     <bean id="conversionService"  
3         class="org.springframework.format.support.FormattingConversionServiceFactoryBean">  
4         <property name="formatters">  
5             <set>  
6                 <bean class="com.online.util.DateFormatter"></bean>  
7             </set>  
8         </property>  
9     </bean>  

在Springmvc.xml中使用 mvc:annotation-driven注解配置

 1 <mvc:annotation-driven conversion-service="conversionService"/> 

 这样就是现了string-->date类型的转换

 

转载于:https://www.cnblogs.com/cmyxn/p/5895093.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值