• 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类型的转换
  • 相关阅读:
    bzoj 3035 二分答案+二分图最大匹配
    bzoj 1058 bst
    bzoj 1093 缩点+DP
    bzoj 1452 二维树状数组
    bzoj 1968 数学
    bzoj 1034 贪心
    牛客小白月赛12 I (tarjan求割边)
    Loj 103、10043 (KMP统计子串个数)
    poj 2356 (抽屉原理)
    hdu 1907 (尼姆博弈)
  • 原文地址:https://www.cnblogs.com/cmyxn/p/5895093.html
Copyright © 2020-2023  润新知