关于ajax传值给后端 日期格式的数据出现错误

博客内容涉及Spring框架中处理日期转换的问题,具体表现为尝试将字符串转换为`java.sql.Date`时失败,错误信息指出日期格式不匹配。解决方案包括在实体类的时间字段上使用`@DateTimeFormat`注解,并修改Mybatis的日期类型为`java.util.Date`。
摘要由CSDN通过智能技术生成

Field error in object 'propertyNotice' on field 'release_date': rejected value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]; codes [typeMismatch.propertyNotice.release_date,typeMismatch.release_date,typeMismatch.java.sql.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [propertyNotice.release_date,release_date]; arguments []; default message [release_date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'release_date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Date] for value 'Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]]]
Field error in object 'propertyNotice' on field 'release_date': rejected value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]; codes [typeMismatch.propertyNotice.release_date,typeMismatch.release_date,typeMismatch.java.sql.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [propertyNotice.release_date,release_date]; arguments []; default message [release_date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'release_date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Date] for value 'Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]]]
Field error in object 'propertyNotice' on field 'release_date': rejected value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]; 

解决办法:

1.在实体类时间字段上面添加注解@Datetimeformat

2.将mybatis自己生成的包改成java.util.Date;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用Django前端传值后端时,可能会遇到一些问题。以下是可能出现的一些常见问题和解决方法: 1. 页面表单提交问题:在表单提交时,可能会出现数据未成功传递到后端的情况。这可能是由于表单的重定向或提交地址不正确导致的。要解决这个问题,可以检查表单的 "action" 属性和 "method" 属性是否正确设置。 2. 数据类型问题:前端可能会将数据以不正确的数据类型传递给后端。例如,前端将字符串传递给后端需要整数的字段。要解决这个问题,可以使用Django的表单验证来验证数据类型并进行相应的类型转换。 3. 跨站请求伪造(CSRF)问题:Django默认开启了CSRF保护,如果前端没有正确的CSRF令牌,将无法成功发送POST请求。要解决这个问题,可以在前端的表单中添加{% csrf_token %}标签,并确保在提交表单时,令牌被正确地发送到后端。 4. 异步请求问题:如果前端使用异步请求(例如AJAX)来传递数据后端,可能会出现数据未成功传递的问题。要解决这个问题,可以检查异步请求的URL是否正确,后端是否正确处理异步请求,并在前端处理成功或失败的回调函数中进行相应的操作。 总之,正确传递前端数据后端的过程涉及到多个环节,包括表单提交、数据类型验证、CSRF保护和异步请求等。在遇到问题时,可以逐一检查每个环节,找出并解决导致数据传递不成功的原因。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值