LocalDateTime 接受前端参数
后端对象
package com.cdn.demo.controller;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
public class User {
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss" )
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime localDateTime;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
前端:
{
"localDateTime": "2023-10-18 16:18:35"
}
结果:
User(localDateTime=2023-10-18T16:18:35)