Java 试图将日期作为路径变量传递给postman,但出现错误
我试图通过使用get映射将日期参数作为path变量传递给邮递员来查询我的数据库,但是我一直收到此错误“我试图通过使用get映射将日期参数作为path变量传递给邮递员来查询我的数据库,但是我一直收到此错误 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]] 我已经尝试过使用网上各种人建议的Java 试图将日期作为路径变量传递给postman,但出现错误,java,spring,spring-boot,Java,Spring,Spring Boot,我试图通过使用get映射将日期参数作为path变量传递给邮递员来查询我的数据库,但是我一直收到此错误“我试图通过使用get映射将日期参数作为path变量传递给邮递员来查询我的数据库,但是我一直收到此错误 org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: 无法将“java.lang.String”类型的值转换为所需类型 'java.sql.Date';嵌套异常为 org.springfram
@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
}
@GetMapping(“/walletledger/{fromDate}/{toDate}/{currencycode}”)
@预授权(“hasAuthority('SUPERADMIN'))
公共列表获取WalletLedgers(
@PathVariable(“fromDate”)@DateTimeFormat(iso=DateTimeFormat.iso.DATE)DATE fromDate,
@PathVariable(“toDate”)@DateTimeFormat(iso=DateTimeFormat.iso.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 - > {
@覆盖
公共列表获取WalletLedgers(
日期fromDate,
今天,
CurrencyCode CurrencyCode,
可寻呼(可寻呼){
ListledgerList=newarraylist<>();
账本存放。查找YesExecutionDate和ExecutionDate以及currencyCode(fromDate,toDate,currencyCode)。forEach(账本->{
要调用的URL
请分享您是如何向邮递员发出请求并使用java.util.Date中的日期的。希望您是以yyyy-MM-dd格式传递值,例如“2000-10-31”格式。是的,我是。示例:“2019-07-24”"下面是我的端点路径url:/2019-07-24/Ngform错误消息我可以看到您试图解析的值
2019-07-24 11:50:34.896+01
这与我正在做的事情是一样的,同样的错误。确保从java.util.Date导入日期它是:import java.util.Date;我刚刚发现缺少货币代码的@PathVariable,它是更改此选项后可能会导致问题
@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();
}
localhost:8888/date/2019-07-25/2019-07-26