SPRINGMVC Related-Formatting tags

Source: Internet
Author: User

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

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.