码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC后台使用对象接受参数字符串转日期

时间:2017-09-20 12:01:14      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:.text   配置文件   factory   mat   except   div   new   property   color   

在springMVC配置文件中加入:
<bean id="dateConvert" class="com.iomp.util.DateConvert"/>
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
        <property name="converters">
            <set>
                <ref bean="dateConvert"/>
            </set>
        </property>
    </bean>
    <mvc:annotation-driven conversion-service="conversionService"/>
对应实现类:
package com.iomp.util;

import org.springframework.core.convert.converter.Converter;

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

/**
  * 对象方式接受页面参数,字符串转日期格式
  * ClassName: DateConvert.
  * User: lyc
  * Date: 2017/9/16
  * Time: 18:29
 */

public class DateConvert implements Converter<String, Date> {
    @Override
    public Date convert(String stringDate) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = null;
        try {
            date = simpleDateFormat.parse(stringDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

}

 

SpringMVC后台使用对象接受参数字符串转日期

标签:.text   配置文件   factory   mat   except   div   new   property   color   

原文地址:http://www.cnblogs.com/super-chao/p/7560234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!