报错信息如下
nopaexpiretimeFailed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'nopaexpiretime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@com.baomidou.mybatisplus.annotation.TableField
@org.springframework.format.annotation.DateTimeFormat java.util.Date] for value '2020-12-21 19:45:27'; nested
exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2020-12-21 19:45:27]
其实是注解上的时间大小写的问题
@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
修改为大写即可
-
结束
-
补充
接收json数据时使用
@JsonFormat(pattern = "yyyy-MM-dd") 时间上添加此注解
@PostMapping(value = "" ,produces = "application/json;charset=UTF-8")
@RequestBody 接收json数据
接收form数据时使用
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Valid 接收form数据 时间上作此注解即可
日常记录工作中遇到的问题,方便以后查阅
2021-01-28补充内容
在使用@JsonFormat注解时,需添加 timezone = “GMT+8”;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
否则时间还是会差8个小时