Springboot (2)---Quickly create a project, the first to solve Jackson

Source: Internet
Author: User
Tags locale

Tag: obj does not have the boot framework to create the private tool Bubuko date ()

Quickly create a project, first solution Jackson

first, quickly create a project

Springboot website provides tool class to automatically create Web apps: url: http://start.spring.io/

Official website surface

1. Quickly create a

Select Web representative This is a Web project

This allows the project to be put into eclipse or idea to run.

Here are a few things to note:

1.SPRINGBOOT2X, the need Mevan is 3.0+,jdk is 1.8+

2. When doing project development, the main entrance application class (annotated @springbootapplication) is placed on top of all packages.

Second, the first solution to Jackson

Jackson is Springboot's own JSON frame.

Jackson Common Tags
(1) The specified field does not return:@JsonIgnore

(2) Specify date format:@JsonFormat (pattern= "Yyyy-mm-dd hh:mm:ss", locale= "zh", timezone= "gmt+8")

(3) Empty field does not return:@JsonInclude (include.non_null)

(4) Specify alias:@JsonProperty

Example:

User Object

 Public classUser { @JsonProperty("Account")    Private intAge ; @JsonIgnore PrivateString pwd; @JsonInclude (include.non_null) PrivateString Phone; @JsonFormat (Pattern = "Yyyy-mm-dd hh:mm:ss", locale= "zh", timezone= "gmt+8")PrivateDate createtime;//provides the set and get methods, the ToString method}
Mapping method in Controller class
@GetMapping ("/testjackson")      Public Object Testjson () {        returnnewnullnew  Date ());    }

the effect Demo Interface test tool is Postman

We found that:

1: DateTime format becomes the specified format

The 2:age property appears in the interface: Account

3:PWD does not show

4: Because the phone property is null, it is not displayed.

GitHub Address: Https://github.com/yudiandemingzi/springbootjackson

Think too much, do too little, the middle of the gap is trouble. Want to have no trouble, either don't think, or do more. Captain "4"

Springboot (2)---Quickly create a project, the first to solve Jackson

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.