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