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 ...
随机推荐
- Windows安装使用Jenkins
#前提条件是要把JDK安装好 1.下载jenkins:https://jenkins.io/download/ 选择windows版本 2.安装成功过后自己会启动 如果想自己启动(这两个需要以管理员方 ...
- MFC的cstring判断是否存在中文字符
bool IsChinese(CString Cstr) { int nLen = Cstr.GetLength(); unsigned char ch1, ch2; for (int i = 0; ...
- redis day03
模拟缓存 django-admin startproject rmysite3 创建django项目 python3 manage.py startapp user 创建py应用 33 行 ...
- navicat中执行PostgreSQL错误解决:ERROR: current transaction is aborted, commands ignored until end of transaction block
错误出现: 含有错误的查询后,选中insert语句无法执行,报错current transaction is aborted, commands ignored until end of transa ...
- Exception in thread "main" java.lang.AbstractMethodError
参考https://stackoverflow.com/questions/15758151/class-conflict-when-starting-up-java-project-classmet ...
- 替换String中的\r\n\t
String json = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n " ...
- PAT甲级——1058 A+B in Hogwarts
1058 A+B in Hogwarts If you are a fan of Harry Potter, you would know the world of magic has its own ...
- demo4j解析xml
1//先加入dom4j.jar包 2import java.util.HashMap; 3import java.util.Iterator; 4import java.util.Map; 5 6im ...
- VS编译release版本的出现的LNK1104 无法打开文件“libboost_filesystem-vc140-mt-1_58.lib
最近在用restbed和vs2015做一个项目,debug编译的没问题,但是编译release就有问题,困扰了一天,说下我的出坑过程. 1.我用到了外部的库 restbed ,首先要想正确编译过,你的 ...
- C语言中传值和C++的传引用
在C语言中,传址其实也时传值的一种,首先地址其实也时可以看做是一个值来进行传递的. 在C++中有一种说法叫传引用,就是&变量名. 比如: /* * 传值 int a = 3; void fun ...