Springboot|Zero date value prohibited

Springboot|Zero date value prohibited
文章图片


最近使用MyBatis时发现了java.sql.SQLException: Zero date value prohibited 的异常,网上查了一下原因。其实是Mysql数据库在面对0000-00-00 00:00:00日期的处理时,如果没有设置对应的对策,就会产生异常。
所以解决的方法是在jdbcUrl中设置处理zeroDateTimeBehavior来处理,一般有下面几种:
1.driver-url=jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL
ZERO日期会转化为null
【Springboot|Zero date value prohibited】注意:CONVERT_TO_NULL 一定是大写的,否则报错

    推荐阅读