Swagger测试更新功能时报HTTP-400错误
原因分析
400 是 HTTP 的状态码,主要有两种形式:
1、bad request 意思是 "错误的请求";
2、invalid hostname 意思是 "不存在的域名"。
通过以上描述,分析发现我这次测试的请求JSON中包含了多余的创建时间、更新时间
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@21f7559] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@2106806583 wrapping com.mysql.cj.jdbc.ConnectionImpl@22bef16] will not be managed by Spring
==> Preparing: SELECT id,name,intro,career,level,avatar,sort,is_deleted,gmt_create,gmt_modified FROM edu_teacher WHERE id=? AND is_deleted=0
==> Parameters: 1(String)
<== Columns: id, name, intro, career, level, avatar, sort, is_deleted, gmt_create, gmt_modified
<== Row: 1, 张三, 近年主持国家自然科学基金(6项)、江苏省重大科技成果转化项目(5项)、江苏省产学研前瞻性联合研究项目(3项)、省工业科技支撑、省高技术、省自然科学基金等省部级及其企业的主要科研项目40多个,多个项目在企业成功转化,产生了较好的经济、社会和环境效益。积极开展产学研科技合作,并与省内16家企业建立了江苏省研究生工作站,其中6家为江苏省优秀研究生工作站, 高级,
1, https://guli-file-190513.oss-cn-beijing.aliyuncs.com/avatar/default.jpg, 0, 0, 2019-10-30 14:18:46, 2019-11-12 13:36:36
<== Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@21f7559]
2022-10-20 11:02:18.782 WARN 12684 --- [nio-8001-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2022-10-20T02:57:23.896Z": not a valid representation
(error: Failed to parse Date value '2022-10-20T02:57:23.896Z': Unparseable date: "2022-10-20T02:57:23.896Z"); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2022-10-20T02:57:23.896Z": not a valid representation (error: Failed to parse Date value '2022-10-20T02:57:23.896Z': Unparseable date: "2022-10-20T02:57:23.896Z")
at [Source: (PushbackInputStream); line: 4, column: 16] (through reference chain: com.bravovax.serviceedu.entity.EduTeacher["gmtCreate"])]
解决方法
删除多余的创建时间、更新时间