Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.util.Date

  • Post author:
  • Post category:java


但前台是String类型值传到后台使用Date接收时,会报Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date错误

解决办法:实体类报错参数上添加注解:

@DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createDateEd; 

对应的Controller参考:

@RequestMapping("logPager")
	public String logPager(SysLog log, HttpServletRequest request, HttpServletResponse response) {
		Page<SysLog> page = new Page<>(log.getPageNo(), null!=log.getSize()?log.getSize():10); //分页参数, 每页log.getPageSize()条,第log.getPageNo()页
		QueryWrapper<SysLog> wrapper = new QueryWrapper();//实体参数
		if(null != log.getCreateDateSt()){
			wrapper.le("createdate", log.getCreateDateSt());
		}
		if(null != log.getCreateDateEd()){
			wrapper.ge("createdate", log.getCreateDateEd());
		}

		wrapper.orderByDesc("createdate");
		IPage<SysLog> logs = logService.page(page,wrapper);
		request.setAttribute("logs", logs);
		setHeaderSuccess(response);
		return "Log";
	}



版权声明:本文为qq3892997原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。