Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

java - How to map timestamp in Spring Rest?

My web service (Spring REST) receives the following POST request:

{
 "id": "1",
 "someKey" : "value",
 "time":"2020-01-01 11:11:11+0000"
}

How can I map the time to a variable?

I use Hibernate for ORM, but the time is saved to the database as "null" when I use Date. I tried to use Timestamp, but got a parse error.

EDIT:

The controller looks like this:

@PostMapping("/endpoint")
public MyData handlePost(@RequestBody MyData mydata){
       return repository.save(mydata);
}
question from:https://stackoverflow.com/questions/65906239/how-to-map-timestamp-in-spring-rest

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ").parse(mydata.getTime());  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...