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