public class UserVo{
/**同时使用@DateTimeFormat、@JsonFormat这两个注解在接收请求时,Spring将使用@DateTimeFormat指定的格式将字符串转换为日期或时间对象,并在响应时,使用@JsonFormat指定的格式将日期或时间对象转换为特定的JSON格式。
**/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonSerialize(using = LocalDateTimeSerializer.class) // Jackson序列化
@JsonDeserialize(using = LocalDateTimeDeserializer.class) // Jackson反序列化
private LocalDateTime createTime;
}
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
添加这两个注解可以解决报错(出现该异常的场景在SpEL表达式的解析中):
java.lang.IllegalArgumentException: Java 8 date/time type java.time.LocalDateTime
not supported by default:
add Module “com.fasterxml.jackson.datatype:jackson-datatype-jsr310” to enable handling (through reference chain…