![](/img/trans.png)
[英]I am trying to get the last date element in a set, however It keeps returning the first one?
[英]Trying to pass a date as a path variable on postman however i get error
我正在尝试通过使用 get 映射在邮递员上传递日期参数作为路径变量来查询我的数据库,但是我不断收到此错误“我正在尝试通过使用 get 映射在邮递员上传递日期参数作为路径变量来查询我的数据库,但是我不断收到此错误
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:无法将“java.lang.String”类型的值转换为所需类型“java.sql.Date”; 嵌套异常是 org.springframework.core.convert.ConversionFailedException:无法从类型 [java.lang.String] 转换为类型 [@org.springframework.web.bind.annotation.PathVariable @org.springframework.format.annotation.DateTimeFormat java.sql.Date] 值 '2019-07-24 11:50:34.896+01'; 嵌套异常是 org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型 [java.util.Date] 转换为类型 [@org.springframework.web.bind.annotation.PathVariable @org.springframework.format 的转换器。 annotation.DateTimeFormat java.sql.Date]]
我已经尝试按照@DateTimeFormat
很多人的建议使用@DateTimeFormat
,但它仍然无法正常工作。
@GetMapping("/walletledger/{fromDate}/{toDate}/{currencycode}")
@PreAuthorize("hasAuthority('SUPERADMIN')")
public List < LedgerResponseDTO > fetchWalletLedgers(
@PathVariable("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
@PathVariable("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate
}
执行
@Override
public List < LedgerResponseDTO > fetchWalletLedgers(
Date fromDate,
Date toDate,
CurrencyCode currencyCode,
Pageable pageable) {
List < LedgerResponseDTO > ledgerList = new ArrayList < > ();
ledgerRepository.findByExecutionDateAndExecutionDateAndCurrencyCode(fromDate, toDate, currencyCode).forEach(ledger - > {
@GetMapping(value = "/date/{from}/{to}")
public String DemoDate(@PathVariable(name = "from") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date from,
@PathVariable(name = "to") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date to)
{
return from.toString() + " "+ to.toString();
}
要调用的 URL
localhost:8888/date/2019-07-25/2019-07-26
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.