mybatis mysql Data truncation: Incorrect integer value: '' for column 'xxx' at row 1

发布时间 2023-11-30 23:34:53作者: kevinZhuZhu

 com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect integer value: '' for column 'n_before_group_id' at row 1

 

mybatis foreach 插入时出现这个报错,原因是某字段插入空值时需要插入NULl而不是‘’

 

解决办法:

<choose>
          <when test="item.xxx == null || item.xxx == ''">
            NULL,
          </when>
          <otherwise>
            #{item.xxx},
          </otherwise>
        </choose>