记录一下MyBatis-plus 提示的错误信息:

### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1
### The error may exist in com/zzg/mapper/ScheduleJobMapper.java (best guess)
### The error may involve com.zzg.mapper.ScheduleJobMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO schedule_job  ( id, job_name, cron_expression, bean_name, method_name )  VALUES  ( ?, ?, ?, ?, ? )
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1
; Data truncation: Out of range value for column 'id' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1] with root cause

com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1

造成上述问题的原因:

可能原因:

1、数据库字段值范围小,插入字段值范围大
        修复:修改数据库字段类型,例如将int改为bigint
2、插入一个临界点的值成功,再次插入则报错
        修复:修改数据库字段类型,例如将int改为bigint
3、使用mybatisplus注解@TableId且没有指定type(或指定为IdType.NONE)
        修复: 指定type=IdType.AUTO

我造成上述原因是主表主键忘记指定增长类型

package com.zzg.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;

@SuppressWarnings("serial")
@TableName(value = "schedule_job")
@Data
public class ScheduleJob implements Serializable {
	@TableId(type = IdType.AUTO)
	private Long id;
	private String jobName;
	private String cronExpression;
	private String beanName;
	private String methodName;
	private Integer status;
	private java.sql.Date createTime;
	private java.sql.Date updateTime;
	private Integer delFlag;
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐