最近在用springboot写一个实战项目,遇到了些问题以及异常。现在总结一下:
1、在进行添加时,出现了id没有默认值

原来是在建数据库时,不小心没有设置id(主键)自动递增。

2、在进行文件上传下载时,文件上传一直报错

然后找了好久,最后确定是教师工号没有获取到,将教师工号integer改为string类型后上传成功。
3、在进行命名规范改包名时,出现如下异常
Caused by: java.lang.ClassNotFoundException: Cannot find class: leaves
是因为找不到这个类,可以去yml文件加上
type-aliases-package: cn.zcbigdata.mybits.entity
或者在xml文件加上
cn.zcbigdata.mybits.entity.Tea
4、在进行命名规范改包名时,还出现了以下异常
Description:Field leavesMapper in cn.zcbigdata.mybitsdemo.service.Impl.LeavesServiceImpl required a bean of type 'cn.zcbigdata.mybitsdemo.mapper.LeavesMapper' that could not be found.The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)Action:Consider defining a bean of type 'cn.zcbigdata.mybitsdemo.mapper.LeavesMapper' in your configuration.
是包名改变了但启动项没有改变,去启动项找
@MapperScan("cn.zcbigdata.mybits.mapper") //扫描的mapper
5、还出现了
Description:Field filepathService in cn.zcbigdata.mybitsdemo.controller.UploadController required a bean of type 'cn.zcbigdata.mybitsdemo.service.FilepathService' that could not be found.The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)Action:Consider defining a bean of type 'cn.zcbigdata.mybitsdemo.service.FilepathService' in your configuration.
去serviceimpl找,service注解有错误

加上service注解即可
然后就是分析问题流程
首先是前台分析
404错误:请求路径错了,前后台路径不一致
405错误:请求方式错了,例如:后台只支持post请求,前台却用了get请求
400错误:前后台参数类型不一致
然后是后台分析
500错误:后台服务错误,后台控制台有错误日志
如果前后台都没有报错
可以在后台打印参数或者idea用debug调试查看每一行代码运行的结果
本文总结了在使用SpringBoot开发实战项目时遇到的一些常见问题及其解决方案,包括:数据库主键id未设置自动递增、文件上传下载的处理、包名更改导致的异常、启动项配置错误以及依赖注入失败等。通过分析错误日志,排查前端请求错误,如404、405、400错误,以及后台500错误,能够有效地定位并解决问题。


被折叠的 条评论
为什么被折叠?



