SPRINGMVC Converter and formatting

Source: Internet
Author: User

SPRINGMVC framework: Formatting and converters

Converter (formatted), Formatter (Converter)

First, Converter class

2, Converter: Any layer can, Formatter: specifically for the web layer design


The converter of 3.Spring is an object that converts one type into another type. Create the converter class as a step:

1.org.springframework.core.convert.converter.converter

The declaration of this interface:

4.public interface Converter<s,t>-S is the source type, T is the target type

Example: Long, double type

Public classname implements converter<long,date>{}

Implementation method:

The T-convert (s source) method is a source type that passes in an S

Focus

1, using the Bean constructor method can be configured to inject

Write Bean---org.springframework.context.support.conversion.ServicefactoryBean;

<properties name = "Converters" >

<list><bean class = "Custom class name full path"/></list>

</properties>

2, define the configuration of a

<mvc:anntation-driven conversion-service = "corresponding Beanid" >

3. Other Precautions:

Use of the bindresulting and Getfielderror () methods

Second, formatter class

1, limit source-string, must be: Source type: Can only be String, apply to Web hierarchy

2. Example: Convert to Type:

public interface formatter<t>

Org.springfamework.format.Formatter

3. Method: Parse (), print ()

4. Configure a Factorybean in the spring configuration file Why not say more, the rest of the converter class is almost as well as to illustrate the formatter-formatterregister implementation Registerformatters Method-Addformatter (Class)



This article is from "Bo Li/alex Blog" blog, reprint please contact the author!

SPRINGMVC Converter and formatting

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.