异常Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
2023-09-11 14:15:14 时间
首先看错误能看出来类型转换错误,我是在Controller层在地址上以斜杠的方式来取参数的时候报错的。
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:
Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';
代码:
@RequestMapping(value = "/deleteHealthExam/{healthExamId}/{healthExamDate}", method = RequestMethod.DELETE)
public ResultDto deleteHealthExam(@PathVariable String healthExamId,
@PathVariable("healthExamDate") Date healthExamDate) {
return healthExamService.deleteHealthExam(healthExamId,healthExamDate);
}
原因:
healthExamDate我是以Date类型去接参数的,但是他默认是字符串类型,这里得需要类型转换一下。
解决方案:
添加@DateTimeFormat注解,让他类型转换成Date类型
@PathVariable("healthExamDate")
@DateTimeFormat(pattern="yyyy-MM-dd")
Date healthExamDate
相关文章
- [Java基础] java多线程关于消费者和生产者
- Jmeter里的全能java测试sampler - Java request
- Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
- Java设计模式----观察者模式详解
- Java实现 LeetCode 394 字符串解码
- Java实现蓝桥杯历届试题格子刷油漆
- 【JAVA】Java 异常中e的getMessage()和toString()方法的异同
- Atitit 搜索蓝牙设备 powershell的实现 java noede.js python 先用脚本语言python nodejs,不好实现。。Java 也不好实现。。 Netcore可以,
- Java 多线程实现的四种方式
- 【java】Java经典面试题整理(附答案)
- android 解决报错 installation failed with message Failed to finalize session : INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed parse during installPackageLI: Failed to read manifest from /xx/xx/xx.apk
- Java如何获取IP属地 ip2region failed to create searcher with x:java.io.FileNotFoundException:( 系统找不到指定的路径)
- java 程序运行的基础知识【Java bytecode】
- JAVA获取随机数
- mysql-connector-java与Mysql、Java的对应版本
- JAVA语言之Java 中不同的并行实现的性能比较