1、后端属性是private LocalDateTime startTime;
2、前端传递日期格式:2021-07-19 20:00:00
请求报错:Cannot deserialize value of type java.time.LocalDateTime from String “2021-07-19 20:00:00”: Failed to deserialize java.time.LocalDateTime
原因:LocalDateTime的格式是“2021-07-19T20:00:00”
解决办法:在实体类上加上注解,如下:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
https://www.cnblogs.com/codecat/p/10845797.html
http://www.hellojava.com/a/90334.html
https://blog.csdn.net/a13794479495/article/details/83892829
https://blog.csdn.net/jcmj123456/article/details/109735097
按以上加了注解之后,在执行sql的时候又会报错:
mybatis 报错 invalid comparison: java.time.LocalDateTime and java.lang.String
原因:在mapper.xml文件中,对该参数进行了和字符串的对比。
<if test="startTime != null and startTime != ''">
and create_time <![CDATA[ >= ]]> #{startTime}
</if>
解决办法:
不判断是否为空字符,改为
<if test="startTime != null">
and create_time <![CDATA[ >= ]]> #{startTime}
</if>