Http Get请求传递Date型参数报错

1.场景

做excel导出时,使用get请求传递时间的格式: 2019-07-31T16:00:00.000Z,调用接口时,报错

Field error in object 'tmsShippingOrderQueryVo' on field 'endTime': rejected value [1565280000000];

2.问题

后台查询的对象的字段startTime是Date类型,类型不一致

3.解决

startTime=2011/12/02 10:50:25 
使用yyyy/mm/dd HH:mm:ss格式传递 
http协议是外国人定的,所以得用外国常用时间格式传递

前端处理: 格式化时间格式

format (time, format) {
  //time 时间戳  format指定时间格式
  format = format === null || format === undefined ? 'yyyy-MM-dd HH:mm:ss' : format
  var t = new Date(time)
  var tf = function (i) {
    return (i < 10 ? '0' : '') + i
  }
  return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
    switch (a) {
      case 'yyyy':
        return tf(t.getFullYear())
      case 'MM':
        return tf(t.getMonth() + 1)
      case 'mm':
        return tf(t.getMinutes())
      case 'dd':
        return tf(t.getDate())
      case 'HH':
        return tf(t.getHours())
      case 'ss':
        return tf(t.getSeconds())
    }
  })
},

后端处理:

入参格式化

使用 Spring 的 @DateTimeFormat 注解格式化参数

出参格式化

@JsonFormat 注解

@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值