spring boot 传递Date 等实体参数时候报错
来源:互联网 发布:电脑免费视频编辑软件 编辑:程序博客网 时间:2024/06/01 18:24
传递参数Date时候报错:"exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException","message": "Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.util.Date] for value '2016-12-27 09:44:58'; nested exception is java.lang.IllegalArgumentException",
swagger2:@ApiImplicitParam(name = "startDate", paramType = "query", value = "生效时间", dataType = "Date"),@ApiImplicitParam(name = "endDate", paramType = "query", value = "失效时间", dataType = "Date"),
params由:
@RequestParam(value = "startDate", required = false) Date startDate,
@RequestParam(value = "endDate", required = false) Date endDate,
改为:
@ModelAttribute Date startDate,@ModelAttribute Date endDate,此时 参数传递正常 但是date值都存在切为当前时间改回@RequestParam(value = "startDate", required = false) Date startDate,@RequestParam(value = "endDate", required = false) Date endDate,
并加入
@InitBinderprotected void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));}
此时参数传递正常
时间段查询条件
if (startDate!=null) {//开始时间 if(endDate!=null){//结束时间 结束时间部位空 查询时间段内数据 predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("endDate").as(Date.class), startDate ));//输入开始时间>=开始生效时间 predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("startDate").as(Date.class), endDate ));//输入结束时间<=失效时间 }else{ predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("startDate").as(Date.class), startDate )); predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("endDate").as(Date.class), startDate )); }}
1 0
- spring boot 传递Date 等实体参数时候报错
- spring boot 启动时候报错mongodb
- spring boot rabbitmq传递bean(实体类)配置
- spring boot 请求参数增加string 转date全局转换器
- Spring Boot报错问题解决
- spring boot启动报错
- spring boot启动报错
- Spring Boot 报错分析
- Spring boot 启动报错
- Spring mvc Date类型参数为空时,controller报错
- spring mvc 表单的实体包含时间Date,double等类型的处理
- Struts2通过实体传递参数
- struts2传递实体类参数
- ibatis传递日期Date参数
- jsp页面传递date到java报错
- Intellij Idea spring boot 报错记录
- spring boot中出现parent报错
- Spring Boot报错Whitelabel Error Page
- 试验:贝塞尔数组点的展开
- Javaweb网cors跨域ajax数据交互
- Kafka常用命令
- Windows 8常用快捷键使用大全
- Java学习之Iterator(迭代器)的一般用法
- spring boot 传递Date 等实体参数时候报错
- 获取本机MAC地址
- 113. Path Sum II
- SqueezeNet模型参数降低50倍,压缩461倍
- Kd-Tree算法原理和开源实现代码
- 【9-1-5】简单链表,链式存储
- Spring AOP自定义注解 身份验证
- 2016.12.27回顾
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter