1 PostMan 模拟异步请求
1.1 请求头
1.2 请求体
1.3 后台代码及错误日志
1.3.1 处理请求的代码
// entity
public class Employee {
private Integer id;
private String lastName;
private String email;
/**
* 1 male, 0 female
*/
private Integer gender;
private Department department;
// 日期对象
private Date birth;
// 省略 setter 和 getter
}
// controller
@RequestMapping(value = "/add",method = RequestMethod.POST)
@ResponseBody
public String addEmp(@RequestBody Employee employee){
System.out.println(employee.toString());
return "{\n" +
" \"message\": [\n" +
" {\n" +
" \"image_src\": \"https://api-hmugo-web.itheima.net/pyg/banner1.png\",\n" +
" \"open_type\": \"navigate\",\n" +
" \"goods_id\": 129,\n" +
" \"navigator_url\": \"/pages/goods_detail/index?goods_id=129\"\n" +
" }\n" +
" ],\n" +
" \"meta\": {\n" +
" \"msg\": \"获取成功\",\n" +
" \"status\": 200\n" +
" }\n" +
"}";
}
1.3.2 错误日志
21:26:24.991 [http-nio-8080-exec-7] WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-12-12 12:02:56": not a valid representation (error: Failed to parse Date value '2020-12-12 12:02:56': Cannot parse date "2020-12-12 12:02:56": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-12-12 12:02:56": not a valid representation (error: Failed to parse Date value '2020-12-12 12:02:56': Cannot parse date "2020-12-12 12:02:56": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
at [Source: (PushbackInputStream); line: 10, column: 13] (through reference chain: com.springboot.template.springbootwebrestfulcrud.entity.Employee["birth"])]
2 分析
- 数据转换异常
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type
java.util.Datefrom String "2020-12-12 12:02:56"
while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX'
2020-12-12 12:02:56的时间字符串表示,无法转换为java.util.Date对象
2020-12-12T12:02:56的时间字符串表示,可以转换为java.util.Date对象
3 结论
后台的时间类型为java.util.Date
前端通过post请求方式,异步发送json数据,时间字符串必须符合'yyyy-MM-dd'T'HH:mm:ss.SSSX'
的模板样式
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由半码博客整理,本文链接:https://www.bmabk.com/index.php/post/69773.html