Formatting is primarily about letting data enter in a particular format, getting the results of a particular style (which can also be attributed to data type conversions, mostly to other types of string types).
Here is an example of @numberformat and @DateTimeFormat notes:
First, for the problem:
When you enter a date, it may be written as the format type of 1990-11-23, which is a string type, and the background is not recognized by the date type, and it needs to be formatted. (@DateTimeFormat)
In the input such as salary, may be 1,000 of the format, here is a string, also need to format, let background recognition. (@NumberFormat)
Ii. Basic Use (method of Use):
1. Configure <mvc:annotation-driven/> in the SPRINGMVC configuration file
1 <Mvc:annotation-drivenConversion-service= "Service"></Mvc:annotation-driven>2 3 <BeanID= "Service"class= "Org.springframework.format.support.FormattingConversionServiceFactoryBean">4 < Propertyname= "Converters">5 <Set>6 <refBean= "Myconverter"/>7 </Set>8 </ Property>9 </Bean>
2. Add @numberformat or @DateTimeFormat annotations to the properties of the target Pojo Object!
@DateTimeFormat
–pattern property: Type is a string. Specifies the mode for parsing/formatting field data, such as: "Yyyy-mm-dd hh:mm:ss"
@NumberFormat
–pattern: Type is String, custom style, such as patter= "#,###";
1 @DateTimeFormat (pattern= "Yyyy-mm-dd")2 private Date birth; 3 4 5 @NumberFormat (pattern= "#,###,###")6 private Integer salary;
Brief introduction of @numberformat and @DateTimeFormat annotations
SPRINGMVC Related-Formatting tags