Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date

前提说明:layui定义的date传入后台返回标题中的错误,后台采用spring boot。
解决方法:在实体类中增加@DateTimeFormat(pattern=“yyyy-MM-dd hh:mm:ss”)注解即可转换

控制器务必加上:@Valid和BindingResult BindingResult
传到后台的数据格式:kfRepairDate: 2018-10-22 10:55:32
控制器:

@ResponseBody
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public Boolean update(@Valid TKfRepair em,BindingResult BindingResult) {
		return t.updateById(em);
	}

前端:

							var ins22 = laydate.render({
								elem : '#kfRepairDate',
								min : '2016-10-14',
								max : '2080-10-14',
								type : 'datetime'
							});

实体类:

	@DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
	@TableField(value="kf_repair_date")
	private Date kfRepairDate;

感谢https://q.cnblogs.com/q/93720/ 陈无问

发布了100 篇原创文章 · 获赞 106 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/lglglgl/article/details/83270440