zoukankan      html  css  js  c++  java
  • SpringMVC中的400错误,The request sent by the client was syntactically incorrect.

    在其他对象属性类型一样情况下,只需要创建一个类,再在springmvc.xml中添加配置:

    package com.ujiuye.common;
    
    import org.springframework.core.convert.converter.Converter;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class DateTimeConverter implements Converter<String, Date> {
        public Date convert(String s) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try{
                Date date = sdf.parse(s);
                return date;
            }catch (Exception ex){
                System.out.println(ex.getMessage());
                return null;
            }
        }
    }
    <!--全局类型转型器-->
        <bean id="converter" class="com.ujiuye.common.DateTimeConverter"></bean>
        <bean id="formattingConversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
            <property name="converters">
                <set>
                    <ref bean="converter"></ref>
                </set>
            </property>
        </bean>
        <mvc:annotation-driven conversion-service="formattingConversionService"/>
    
    <mvc:annotation-driven/>
  • 相关阅读:
    正则表达式
    iOS获取设备型号、设备类型等信息
    Dubbo-Zookeeper安装
    CentOS-常用安装
    多线程-线程通信
    JVM-高效并发
    静态代理与JDK动态代理
    JVM-类加载机制
    RPC原理及实现
    JVM-自动内存管理机制
  • 原文地址:https://www.cnblogs.com/chen4j/p/11945393.html
Copyright © 2011-2022 走看看