1、使用注解@DateTimeFormat
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime localDateTime;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate localDate;
@DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime localTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date date;
注解形式不能支持application/json传参请求
2、使用InitBinder
@RestControllerAdvice
public class BaseController {
@InitBinder
public void binder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(LocalDateTime.class, new LocalDateTimeConvertEditor());
dataBinder.registerCustomEditor(LocalDate.class