建设行业信息和技术应用服务网站,网页设计html代码大全超链接,jsp网站开发详解 下载,基层建设被哪些网站全文收录文章目录 问题现象排查解决GET加注解解决使用POST方式解决 时间戳传参失败 问题现象
项目使用的是Spring Cloud微服务#xff0c;服务间调用使用的是Feign在一次服务调用时#xff0c;发现GET传参丢失#xff0c;没有传递过去任何参数加了RequestParam注解#xff0c;发现… 文章目录 问题现象排查解决GET加注解解决使用POST方式解决 时间戳传参失败 问题现象
项目使用的是Spring Cloud微服务服务间调用使用的是Feign在一次服务调用时发现GET传参丢失没有传递过去任何参数加了RequestParam注解发现还是传参失败传递的参数有2个1个是一个Long类型主键ID一个是查询VO
排查解决
GET加注解解决
要使用GET只能将封装的查询VO改为一个个参数确保在Feign接口的对应请求方法上正确使用RequestParam注解并传入正确的参数名称确保RequestParam注解中指定的参数类型与Feign接口中方法的参数类型一致在服务的接口方和调用方都要使用RequestParam注解服务方标明接收GET请求
使用POST方式解决
RequestParam针对单个参数可以使用对于对象示例无法使用但是传递多个参数时使用对象封装比较简单也比较优雅这就需要使用RequestBody注解只能使用POST方式最终测试发现使用POST方式传参同时增加 RequestBody注解可以解决这个问题同样在服务的接口方和调用方都要使用RequestBody注解服务方标明接收POST请求
时间戳传参失败
解决传参问题后发现在传递时间戳类型timeStamp参数时解析失败主要是格式问题无法解析报错如下
2023-08-31 15:36:23.971 ERROR 78816 --- [ XNIO-1 task-7] SituationAnalysisIntersectionExtentService : getEventDetailList:
Error while extracting response for type [java.util.Listcom.newatc.api.situationanalysis.vo.SituationAnalysisIntersectionVO] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error:
Cannot deserialize value of type java.time.Instant from String 2023-08-31 15:35:05: Failed to deserialize java.time.Instant: (java.time.format.DateTimeParseException) Text 2023-08-31 15:35:05 could not be parsed at index 10;
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.Instant from String 2023-08-31 15:35:05: Failed to deserialize java.time.Instant: (java.time.format.DateTimeParseException) Text 2023-08-31 15:35:05 could not be parsed at index 10at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 17] (through reference chain: java.util.ArrayList[0]-com.newatc.api.situationanalysis.vo.SituationAnalysisIntersectionVO[timeStamp])由于两边的程序使用的是不同的日期参数类型一边是Date一边是Instant无法调和最终决定传参市统一使用StringYYYY-MM-dd HH:mm:ss字符串传参问题解决