JSON parse error: Cannot deserialize value of type `java.util.Date` from String
DateTimePicker + @DateTimeFormat("yyyy-MM-dd HH:mm:ss")日期格式转换异常
最近在做的一个项目使用的日期格式是yyyy-MM-dd HH:mm:ss格式的,在后端Java与MySQL这边的转换中一开始格式没有统一间歇性的就会报异常,后面采用了一个@DateTimeFormat("yyyy-MM-dd HH:mm:ss")注解标注在属性上规范了 Date 类型属性的格式(埋坑~)

在前端这边使用的是ElementUI的日期时间组件DateTimePicker
<div class="block">
<span class="demonstration">默认</span>
<el-date-picker
v-model="value1"
type="datetime"
placeholder="选择日期时间">
</el-date-picker>
</div>
使用该组件进行新增操作的时候一直抛异常
JSON parse error: Cannot deserialize value of type java.util.Date from String "2020-01-30T16:00:00.000Z"
网上搜了好多资料,几乎都是说在后端属性上添加注解的
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonField(format = "yyyy-MM-dd HH:mm:ss" )
这些注解都尝试过,都不能解决问题,一直修改重启修改重启搞的贼烦躁,后面在大佬的提示下去看了Element官网文档,在DateTimePicker这个组件的Attributes中看到了format
format 显示在输入框中的格式 string 见日期格式 yyyy-MM-dd HH:mm:ss
日期格式
使用format指定输入框的格式;使用value-format指定绑定值的格式。
默认情况下,组件接受并返回Date对象。以下为可用的格式化字串,以 UTC 2017年1月2日 03:04:05 为例:
请注意大小写
格式 含义 备注 举例
yyyy 年 2017
M 月 不补0 1
MM 月 01
W 周 仅周选择器的 format 可用;不补0 1
WW 周 仅周选择器的 format 可用 01
d 日 不补0 2
dd 日 02
H 小时 24小时制;不补0 3
HH 小时 24小时制 03
h 小时 12小时制,须和 A 或 a 使用;不补0 3
hh 小时 12小时制,须和 A 或 a 使用 03
m 分钟 不补0 4
mm 分钟 04
s 秒 不补0 5
ss 秒 05
A AM/PM 仅 format 可用,大写 AM
a am/pm 仅 format 可用,小写 am
timestamp JS时间戳 仅 value-format 可用;组件绑定值为number类型 1483326245000
[MM] 不需要格式化字符 使用方括号标识不需要格式化的字符 (如 [A] [MM]) MM
因为使用的是动态变量,所以在在该组件中添加了value-format属性,设置了与后台对应的格式
<div class="block">
<span class="demonstration">默认</span>
<el-date-picker
v-model="value1"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetime"
placeholder="选择日期时间">
</el-date-picker>
</div>
翻了大半天的资料,终于解决了问题,得记录一下,学习起来才行!
https://editor.csdn.net/md/?articleId=104067771
JSON parse error: Cannot deserialize value of type `java.util.Date` from String的更多相关文章
- JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
在使用Postman测试Spring Boot项目接口时,接口返回JSON parse error: Cannot deserialize value of type `java.time.Local ...
- 【开发遇到的问题】Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(JSON parse error: Can not deserialize value of type java.util.Date from String[)
1.问题排查 - 项目配置 springboot 2.1 maven配置jackson - 出现的场景: 服务端通过springmvc写了一个对外的接口,查询数据中的表,表中有一个字段属性是时间戳,返 ...
- JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
问题原因所在:前端Vue传输的数据字段类型和后端实体类字段不一致. 我的实体类字段是int类型.前端传输的数据是布尔类型. 文章目录 1.后端方法 2.实体类字段 2.前端传输的数据 1.后端方法 @ ...
- JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc
代码程序: @PostMapping("selectById") @ResponseBody public Result selectById(@RequestBody int i ...
- JSON parse error: default constructor not found. class java.time.YearMonth; nested exception is com.alibaba.fastjson.JSONException: default constructor not found. class java.time.YearMonth
java8新出的YearMonth可以方便的用来表示某个月.我的项目中使用springmvc来接收YearMonth类型的数据时发现 x-www-from-urlencoded 格式的数据可以使用&q ...
- org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-
Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...
- Java 异常 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'
查询时发送给服务器的日期的字符串格式:yyyy-MM-dd HH:mm:ss 服务器接收到日期的字符串之后,向 MySQL 数据库发起查询时,因为没有指定日期时间格式,导致字符串数据不能正确地转换为日 ...
- 前台传参数时间类型不匹配:type 'java.lang.String' to required type 'java.util.Date' for property 'createDate'
springMVC action接收参数: org.springframework.validation.BindException: org.springframework.validation.B ...
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found
今天在完成项目的时候遇到了下面的异常信息: 04-Aug-2014 15:49:27.894 SEVERE [http-apr-8080-exec-5] org.apache.catalina.cor ...
随机推荐
- mac 编程环境
新mac (EI Capitan),需要在python中使用xgboost,通过pip安装未成功. 配置pip cat $HOME/Library/Application\ Support/pip/p ...
- selector.xml的使用
TextView: <TextView android:id="@+id/resetfragment_btn" app:layout_constraintTop_toBott ...
- A brief introduction to complex analysis
\(\underline{Def:}\)A func \(U(\subset \mathbb{C}) \stackrel{f}\longrightarrow \mathbb{C}\)is (compl ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- Asexual inheritance
Asexual inheritance 1,2分别是两种基因型 N1,N2是两种基因型的亲代个数,Wt是t代后每一个每一个基因型的后代数 N1’,N2’是t代后1,2,基因型的个体数 the prop ...
- arm汇编几个经典例题
这几个例题来自我们的上机实验,通过这几个例题基本上能掌握arm汇编一些最基本的操作 arm汇编实现1-100的加法 12345678910111213 AREA Example1,CODE,READO ...
- DjangoBlog部署教程
本篇文章将会手把手教你如何部署DjangoBlog项目,首先介绍下我这里的基本环境,请大家仔细阅读此部分,下面的教程都会使用这些约定来介绍: 系统是ubuntu 18.04 LTS 假设你的域名是ww ...
- django框架进阶-分页-长期维护
################## 分页 ####################### 分页, django有自己内置的分页,但是功能不是很强大,所以自己写一个分页, web页面数据非常 ...
- string判断是否是正常的ip格式
废话不多说,上代码 bool isCurrectIP(char *ip) { if (ip == NULL) { return false; } char temp[4]; int count = 0 ...
- HashMap、Hashtable、ConcurrentHashMap、ConcurrentSkipListMap对比及java并发包(java.util.concurrent)
一.基础普及 接口(interface) 类(class) 继承类 实现的接口 Array √ Collection √ Set √ Collection List √ Collection Map ...