Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize value of type `java.util.Date` from String "2020-03-16T16:00:00.000Z": expected format "yyyy-MM-dd hh:mm:ss"; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException:
Cannot deserialize value of type `java.util.Date` from String "2020-03-16T16:00:00.000Z": expected format "yyyy-MM-dd hh:mm:ss"
at [Source: (PushbackInputStream); line: 1, column: 41] (through reference chain: com.fern.vhr.model.Employee["birthday"])]
一看请求头才发现前端传的的时间格式和后端的时间格式不一样
前端的传的是UTC时间(世界统一时间)
2020-03-09T16:00:00.000Z
上面字母T是日期与时间的分割符
,Z字符表示UTC统一时间
解决办法如下:
首先安装moment.js:
npm install moment -s
在main.js导入moment.js:
import moment from “moment”
//添加到Vue实例中以便全局使用
Vue.prototype.$moment = moment;
使用方法:
this.empForm.birthday=this.moment(this.empForm.birthday).format('YYYY-MM-DD HH:mm:ss');