Jackson/fastjson, MyBatis, MySQL Date/datatime/timestamp, Java date/timestamp Relationship detailed

Source: Internet
Author: User

Jackson/fastjson Serialization/deserialization:

By default, Jackson/fastjson serializes the Java date/timestamp type to a timestamp, which is the number of milliseconds since 0 o'clock on January 1, 1970. If you want to display a user-friendly representation:

Jackson can:

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Objectmapper.setdateformat (SDF)
Or:
@JsonFormat (locale= "zh", timezone= "gmt+8", pattern= "Yyyy-mm-dd HH:mm:ss")

Fastjson can:
@JSONField (format="Yyyy-mm-dd HH:mm:ss")
Or:

The first method:
Json. Deffault_date_format = "YYYY-MM-DD";
String str = json.tojsonstring (User,serializerfeature.writedateusedateformat);

The second method:

JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss.SSS")
=================
Timestamp datetime type corresponding to MySQL
Timestamp corresponds to MySQL's timestamp type date will correspond to MySQL's date type  <result column="Modified_date"   Jdbctype="TIMESTAMP" property="modified_date" javatype=" java.sql.Timestamp"/> 
<result column="date" jdbctype="date" property="date" javatype=" Java.util.Date " />
Fields indicated: #{modified_date,jdbctype=timestamp}, #{date,jdbctype=date}

For specific reference: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-type-conversions.html

Jackson/fastjson, MyBatis, MySQL Date/datatime/timestamp, Java date/timestamp Relationship detailed

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.