python requests 请求 java 服务的 Date类型参数

java springboot 的HTTP接口 有Date 类型的参数,python 要访问怎么传Date参数呢?

解决方法如下:

python传字符串参数就可以了

data = {"cityCode": "130400", "lineId": "171", "direction": 0, "list": [{'startTime': "2020-06-23 10:00:00"}],
        "start": "2020-06-23 10:00:00", "end": "2020-06-23 10:00:00",
        "targetDate": "2020-06-23"}
re = requests.post("http://localhost:8087/manual/batchAdd", json.dumps(data),
                   headers={"Content-Type": "application/json"})

 

同时 java 的Date 类型参数要加一个注解  @JsonFormat  ,这样python就可以传yyyy-MM-dd HH:mm:ss格式的字符串参数了

 

    @RequestMapping("/batchAdd")
    public void add(@RequestBody Params params) {

    }
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lty.dispatch.entity.Plan;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class Params {

    String cityCode;
    String lineId;
    Integer direction;
    List<Plan> list;

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

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

    @Override
    public String toString() {
        return "Params{" +
                "cityCode='" + cityCode + '\'' +
                ", lineId='" + lineId + '\'' +
                ", direction=" + direction +
                ", list=" + list +
                ", start='" + start + '\'' +
                ", end='" + end + '\'' +
                ", targetDate='" + targetDate + '\'' +
                '}';
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值