Spring 3.2 Custom Parameter binding--date format converter

Source: Internet
Author: User
Tags date format converter

SPRINGMVC configuration file

<!--  Instead of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping and ORG.SPRINGFRAMEWORK.WEB.SERVLET.MVC . method.annotation.requestmappinghandleradapter --><mvc:annotation-driven conversion-service= " Conversionservice "></mvc:annotation-driven><!--  Custom parameter binding  --><bean id=" Conversionservice " class=" Org.springframework.format.support.FormattingConversionServiceFactoryBean ">     <property name= "Converters" >         <list>        <!--  Date type conversions  -->             <bean class= "converter. Customdateconverter "></bean>        </list>     </property></bean> 


Spring provides a converter external interface that can inject its own written converter converter

A custom parameter binding component needs to be injected into the processor adapter, and this example interfaces in the annotation driver

Conversion-service= "Conversionservice"

Custom Date Converters

Package converter;import java.text.parseexception;import java.text.simpledateformat;import  java.util.Date;import org.springframework.core.convert.converter.Converter;public class  customdateconverter implements converter<string, date> {    @ Override    public date convert (String source)  {    The      //implementation converts a date string into a date type, formatted as a yyyy-mm-dd hh:mm:ss         simpledateformat simpledateformat = new simpledateformat ("Yyyy-MM-dd HH: Mm:ss ");        try {                         return  simpledateformat.parse (source);        } catch  ( Parseexception e)  {            e.printstacktrace ();         }        return null;     }}

This article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1729314

Spring 3.2 Custom Parameter binding--date format converter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.