Convert String to Date Time from Request Query String, payload of x-www-urlencoded or form-data

1
2
3
4
@GetMapping("testDateTime1")
public String testDateTime(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date dateTime) {
...
}
1
2
3
4
5
6
7
8
@RequestMapping("testDateTime2")
public String testDateTime2(QueryVo queryVo) {
...
}
public class QueryVo {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date dateTime;
}

Convert String to Date Time from Request payload of application/json

1
2
3
4
5
6
7
8
9
10
@PostMapping("testDateTime3")
public String testDateTime3(@RequestBody QueryVo queryVo) {
System.out.println("testDateTime");
return queryVo.toString();
}

public class QueryVo {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date dateTime;
}