IDEA中操作数据库插入数据报错异常(博客项目插入评论)
bug1
问题
Caused by: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'article_id' at row 1
原因
字面意思是插入的数据值超过article_id列的范围
解决方案
查看对应的数据库字段类型并修正
article_id字段将int修改为bigint
bug2
问题
解决分布式id过长前端解析损失精度
解决方案
实体类对应字段加注解
@JsonSerialize(using = ToStringSerializer.class) //将long类型id转换为String,
实例
public class CommentVo {
@JsonSerialize(using = ToStringSerializer.class) //将long类型id转换为String,解决分布式id过长前端解析损失精度
private Long id;
private UserVo author;
private String content;
private List<CommentVo> childrens;
private String createDate;
private Integer level;
private UserVo toUser;
}
其他方案
返回类型使用map进行处理转化为字符串
// 注意id精度损失问题,方法二
// Map<String,String> map = new HashMap<>();
// map.put("id",article.getId().toString());
// return Result.success(map);