项目报错信息如下:java.text.ParseException: Unparseable date: “Wed Aug 03 2022 00:00:00 GMT+0800 (中国标准时间)“

项目介绍

前端用的element UI,后端就ssm框架。

需求阐述

根据数据的唯一标识id来修改数据的时间,前端代码如下:

		<el-table-column label="测试日期" min-width="150">
                <template slot-scope="scope">
                    <el-col :span="11">
                        <el-date-picker type="date" format="yyyy-MM-dd" placeholder="选择日期" v-model="scope.row.testTime"
                                        style="width: 100%;"></el-date-picker>
                    </el-col>
                </template>
            </el-table-column>

后端接收代码如下:

	@ResponseBody
    @RequestMapping(value = "/updaTetestTime", method = RequestMethod.POST)
    public ResponseProtocol updaTetestTime(@RequestParam(value = "id") String id, @RequestParam("testTime") Date testTime) {}

报错信息如下:

java.text.ParseException: Unparseable date: "Wed Aug 03 2022 00:00:00 GMT+0800 (中国标准时间)"

报错原因

因为前端在传过来值的时候没有做值的解析,所以传过来的是"Wed Aug 03 2022 00:00:00 GMT+0800 (中国标准时间)"这种类型的,要解析成时间戳传给后端。

解决方案

在前端代码上添加一句代码:value-format="timestamp"即可。

		<el-table-column label="测试日期" min-width="150">
                <template slot-scope="scope">
                    <el-col :span="11">
                        <el-date-picker type="date" format="yyyy-MM-dd" placeholder="选择日期" v-model="scope.row.testTime"  value-format="timestamp"
                                        style="width: 100%;"></el-date-picker>
                    </el-col>
                </template>
            </el-table-column>

版权声明:本文为weixin_44826970原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。