<spring-boot-06>2025/7/8-2025/7/9

程序运行报错



  • 第一个错误: 空指针异常(NPE)
    查询数据库全部信息时报错
    错误代码1:System.out.println(studentMapper.selectStudent());
    错误代码2:private EmpMapper empMapper;
    错误原因: 忘记为代码2添加注解 @Autowired ,导致selectStudnet()方法未被连接;


  • 第二个错误
    未找到数据库
    SQL语法错误异常(SQLSyntaxErrorException)
    错误代码:SpringBootMybatisApplication文件;
    错误原因: 忘记添加注解 @MapperScan,导致MyBatis没能扫描到Mapper接口;


  • 第三个错误
    错误内容:
    [Loading class ``com.mysql.jdbc.Driver'. This is deprecated. The new driver class is ``com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.]
    错误原因: 驱动过时...?不对,application.properties文件问题,直接从另一个项目中复制过去的内容,导致指向问题...?现已重写,未引发相同错误;
    奇奇怪怪的


  • 第四个错误
    路径未匹配到
    无可用bean异常(NoSuchBeanDefinitionException)
    错误代码: @MapperScan
    错误原因: 注解内的路径多填写了一级,直接指向了接口文件StudentMapper;


  • 第五个错误
    image
    SQL语法错误异常(SQLSyntaxErrorException)
    错误代码:@Insert("insert into student values (#{id},#{name},#{no},#{gender},#{phone},#{idCard},#{degree},#{graduationDate},#{createTime},#{updateTime},)")
    错误原因: 多写了一个逗号,导致引发;


  • 第六个错误
    image
    SQL完整性约束违规异常(SQLIntegrityConstraintViolationException)
    错误原因: 没注意数据已经被添加过,再次测试运行试图添加重复的数据;


  • 第七个错误
    image
    语法错误异常(SQLSyntaxErrorException)
    错误代码:@Update("update student set no=#{no}, phone=#{phone},idCCard=#{idCard} where id=#{id}")
    错误原因: 属性变量错误,身份证号在数据库中字段名是id_card,而在Student页面中设置的是idCard,在注解中设置修改字段的字段名应该用数据库中的字段名,而不是Student类中的属性名;此外,注解中#{}中的变量名要与被注解的类中的形参名保持一致;


  • 第八个错误
    image
    程序执行异常(ExecutorException)
    错误代码:
    <select id="selectStudentId"> select * from student </select>
    错误原因: 没有写resultType语句,MyBatis找不到映射实体类


  • 第九个错误
    image
    期望值过多异常/结果过多异常(TooManyResultsException)
    错误代码:
    <select id="selectStudentId" resultType="com.itheima.pojo.Student"> select * from student </select>
    错误原因: xml文件中未设置条件,导致MyBatis把数据库的内容全部映射过来


  • 第十个错误
    image
    错误代码:
    <delete id="deleteStudentId"> delete from student where= #{id} </delete>
    错误原因: 眼飘了,直接where=#{id}了,少写了个id,应该是where id = #{id}.


  • 第十一个错误
    image
    SQL错误(SQLError)
    错误代码:
    <insert id="insertEmp" useGeneratedKeys="true" keyProperty="id"> insert info emp values (#{id},#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{createTime},#{updateTime}) </insert>
    错误原因: 一个字母写错了,into写成了info

posted on 2025-07-09 17:47  上官徵羽  阅读(19)  评论(0)    收藏  举报

导航