The understanding of SPRINGMVC

Source: Internet
Author: User
Tags json

Are the personal understanding of SPRINGMVC;

@DateTimeFormat (pattern= "Yyyy-mm-dd HH:mm:ss")
@JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss", timezone = "gmt+8")

1 parsing/formatting of the field level

Add @DateTimeFormat (pattern= "Yyyy-mm-dd HH:mm:ss") to the attribute or get method of the entity class.

The date string in the form is correctly converted to the date type. There are also @numberformat annotations,

Detailed

@Number: Define number-related parsing/formatting metadata (common style, currency style, percent style) with the following parameters:

Style: Used to specify style type, including three kinds: Style.number (Universal Style) style.currency (currency style) Style.percent (Percent style), default style.number;

Pattern: Custom style, such as patter= "#,###";

@DateTimeFormat: Define date-related parsing/formatting metadata with the following parameters:

Pattern: Specifies a pattern for parsing/formatting field data, such as "Yyyy-mm-dd HH:mm:ss"

ISO: Specifies the ISO mode for parsing/formatting field data,

Includes four types: Iso.none (not used)

Iso. DATE (YYYY-MM-DD)

Iso. Time (HH:MM:SS. SSSZ)

Iso. Date_time (Yyyy-mm-dd hh:mm:ss. SSSZ),

Default Iso.none;

2

@JsonFormat annotation, after it is configured on the Get method of the date type,

Jackson will convert the date type in the configured format without customizing the converter class

3

Spring can return objects, and the object is converted to JSON data in a format returned;

Of course you can also use Response.getwriter (). Write to return the format of the JSON data.

Three Jackson bags: Jackson-core.jar, jackson-databind.jar,j Ackson-annotations.jar


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.