当前位置:网站首页>Swagger (or postman) about the parameter transfer method of date type
Swagger (or postman) about the parameter transfer method of date type
2022-07-20 17:12:00 【Secular big tail bear】
Preface : Debugging interface is often used Swagger perhaps Postman, But it is easy to have problems when encountering date types .
post The request may report the following exception :
Can not deserialize value of type java.util.Date from String "2020-08-01 00:00:00": not a valid representation (error: Failed to parse Date value '2020-08-01 00:00:00': Can not parse date "2020-08-01 00:00:00Z": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'', parsing fails (leniency? null))
get The request may report the following exception :
Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @io.swagger.annotations.ApiParam java.util.Date] for value '2020-08-12T06:25:39.929Z'; nested exception is java.lang.IllegalArgumentException
All in all, it's because JAVA The field that accepts the date in the code cannot recognize the date type passed by the debugging tool , Now let's solve this problem .
One .post request
Solution -1
Directly in accordance with the swagger The type of prompt is passed in ,swagger The default date format is as follows :
But this approach needs attention , The time here is standard XML Schema Of " Date data format ”,T Yes, followed by “ Time ”.Z representative 0 The time zone , Or call it UTC Unify time (UTC General standard time ). So if you want to receive the time you want , It is necessary to subtract 8 Hours . For example, the time you want is 2020-08-12 12:10:50, Then the time you need to send it is 2020-08-12T04:10:50.000Z.
Reference resources :utc How to convert time into Beijing time
Solution -2
If you think the solution -1 The time format in this way is too troublesome , You can set JAVA The field in the code that accepts the date , Set the time format you are used to .
The setup code is as follows ( Add... To the field @JsonFormat annotation ):
public class AttendanceResultStatisticsQryParam {
@ApiModelProperty(required = true,example = "1997-01-01 00:00:00",value = " date ")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date time;
}
After setting, you can follow yyyy-MM-dd HH:mm:ss Enter the time in this time format , as follows :
Solution -3
Reference resources :Postman in POST Request delivery date Type parameter
Two .get request
get The requested date type parameter is relatively simple , stay Swagger and Postman The time format is :2020/08/12 00:00:00.
Reference resources :Postman in GET Request to pass in date Type parameter
边栏推荐
- C2AE: Class Conditioned Auto-Encoder for Open-Set RecognitionCVPR2019开放集识别论文解读
- Towards Open World Object Detection
- The best realization of mobile end adaptation with rem/vw units
- 为什么重写equals方法时必须重写hashCode方法
- Worthington核心酶——脱氧核糖核酸酶 I
- redis中RDB和AOF两种持久化方式的比较
- Improve the mirror station configuration information - mirror station experience Officer
- 【综合笔试题】难度 4/5,字符处理的线段树经典运用
- Distance-Based Background Class Regularization for Open-Set Recognition
- OPEN-SET RECOGNITION WITH GRADIENT-BASED REPRESENTATIONS
猜你喜欢
# 搭建用户行为分析系统(一)——概述
零拷贝真的很重要!!!
OpenGAN: Open-Set Recognition via Open Data Generation
为什么重写equals方法时必须重写hashCode方法
One-vs-rest network-based deep probability model for open set recognition解读
Zero copy is really important!!!
如何选择合适的体育场馆用LED显示屏
Analyze QPS, TPS and other basic concepts from the perspective of multithreading
FRP实现内网穿透通过公网服务器实现对外暴露内网服务
消息中间件如何确保消息100%投递成功及消息的幂等性设计
随机推荐
@Value和ConfigurationProperties的区别和使用
Niuke multi school 1 C grab the seat!
Distance-Based Background Class Regularization for Open-Set Recognition
Ampere Altra Max 提供可持续的高分辨率 H.265 编码
Push rejected: Push to origin/master was rejected
Interactive drawing of complex tables from the perspective of app
Human cell research: prosci LAG-3 recombinant protein scheme
Applet learning notes - Cloud Development
Redis 如何分析慢查询操作?
【JDBC】数据库增删改查操作的封装
如何选择合适的体育场馆用LED显示屏
舍友一边玩云顶一边掌握二叉树(超详细)
How does redis analyze slow query operations?
完善镜像站配置信息 — 镜像站体验官
LabView实验——温度检测系统(实验学习版)
uni-app
A. Difference Operations(思维)
零拷贝真的很重要!!!
rtsp转h5播放
9.进程通信