方法genSnapshot执行异常,对应要执行的sql中出现字段“view_count”不能为null的异常,但sql中已经默认赋值0

来源:2-2 新建SpringBoot项目【标准SpringBoot项目目录结构】

qq_魔幻蓝诗_0

2021-07-28

启动项目时,方法genSnapshot中在执行EbookSnapshotMapperCust映射文件里对应方法要执行的sql时报了异常,看了看这个要执行插入操作的sql,字段view_count是有赋默认值0的,但是依旧报了“字段view_count不能为null”的异常,这是这个字段的数据类型改了吗?

Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘view_count’ cannot be null

The error may exist in file [D:\java学习项目\jiawawiki\target\classes\mapper\EbookSnapshotMapperCust.xml]

SQL: insert into ebook_snapshot(ebook_id, date, view_count, vote_count, view_increase, vote_increase) select t1.id, curdate(), 0, 0, 0, 0 from ebook t1 where not exists(select 1 from ebook_snapshot t2 where t1.id = t2.ebook_id and t2.date = curdate()); update ebook_snapshot t1, ebook t2 set t1.view_count = t2.view_count, t1.vote_count = t2.vote_count where t1.date = curdate() and t1.ebook_id = t2.id; update ebook_snapshot t1 left join (select ebook_id, view_count, vote_count from ebook_snapshot where date = date_sub(curdate(), interval 1 day)) t2 on t1.ebook_id = t2.ebook_id set t1.view_increase = (t1.view_count - ifnull(t2.view_count, 0)), t1.vote_increase = (t1.vote_count - ifnull(t2.vote_count, 0)) where t1.date = curdate();

写回答

1回答

甲蛙

2021-07-29

这里需要在service insert之前,把view_count设置成0,在后面会讲到default不起作用

1
0

Spring Boot+Vue3前后端分离,实战wiki知识库系统

一课掌握前后端最火框架,更有职场竞争力

2530 学习 · 1674 问题

查看课程