Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example
[no_toc]
In the tutorial, we build a SpringBoot RestAPIs example that post/get data with java.util.Date
time and save it to MySQL/PostgreSQL database using Spring JPA. Working with Java Date Time is an exciting part but also not easy task, fortunately we have the supporting from utilities of Jackson lib, now the job can be done in an easy way.
Let’s do details by steps!
@JsonFormat
annotation of Jackson, we can use it to format a specific field in Java model:
public class DateTimeModel {
@JsonFormat(pattern="yyyy-MM-dd")
private Date date;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date datetime;
...
}
timezone
attribute of the @JsonFormat
:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="Europe/Paris")
private Date datetimewithzone;
application.properties
:
Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example
#java #springboot #springjpa #restapi