java date localdate_使用LocalDate类型参数发送请求

“2018-05-31 15:40:29.623 WARN 11496 --- [nio-8080-exec-5] .wsmsDefaultHandlerExceptionResolver:无法绑定请求元素:org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:转换失败类型'java.lang.String'的值为必需类型'java.time.LocalDate';嵌套异常是org.springframework.core.convert.ConversionFailedException:无法从类型[java.lang.String]转换为类型[@ org.springframework.web.bind.annotation.RequestParam @ org.springframework.format.annotation.DateTimeFormat java.time.LocalDate] for value'2018-03-22';嵌套异常是java.lang.IllegalArgumentException:解析尝试失败 Value [2018-03-22]“

问题很明显,所以我找到了解决方案并改变了一切,我的方法看起来像这样:

@RequestMapping(path = "reports/daily", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE)

public String getDailyReport(@RequestParam ("start_date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate, @RequestParam("end_date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate) {

double totalDistance = 0.0;

double totalPrice = 0.0;

List transits = transitService.getTransits(startDate, endDate);

for (Transit transit : transits) {

if (transit.getDistance() != null && transit.getPrice() != null) {

try {

totalDistance = totalDistance + transit.getDistance();

totalPrice = totalPrice + transit.getPrice();

} catch (NullPointerException e) {

e.fillInStackTrace().getMessage();

}

}

}

return "Total distance " + totalDistance + ", total price: " + totalPrice;

}

对我来说一切似乎都很好,我还为pom文件添加了所需的依赖 . 谁能帮我?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值