mybatis报错整理

mybatis报错整理

1. 报错一
org.apache.ibatis.binding.BindingException: Type interface spring.wmm.mapper.StudentMapper is not known to the MapperRegistry.
从报错信息的解读我们可以看见报错信息中可以看出几个关键词1.interface(接口)2.StudentMapper 3.not known(不知道) MapperRegistry(映射注册),从几个字面意思我们可以大概知道是跟我们编写的接口有关,说明我们的接口和映射文件之间没有进行绑定。
上面提到的StudentMapper是自己编写的接口,非固定词,如我在项目中的接口名
在这里插入图片描述
解决问题:
打开该mybatis的全局配置文件,在里面添加如下内容:
在这里插入图片描述

  1. 报错二
    org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.(大概翻译:服务器时区值“äÐúêêê×¼Êêêêêêêêêêêê。如果要利用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值)### The error may exist in spring/wmm/mapper/StudentMapper.xml### The error may involve spring.wmm.mapper.StudentMapper.stusList### The error occurred while executing a query### Cause: java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    遇到这种异常只需要在我们项目mybatis全局配置文件中的
    jdbc:mysql://localhost:3306/servlet后面添加上?serverTimezone=UTC
    "jdbc:mysql://localhost:3306/servlet?serverTimezone=UTC”
    在这里插入图片描述

  2. 报错三:
    Error building SqlSession.### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
    出现这种错误是因为我们在mybatisconfig.xml配置文件中添加中文(也包括注释),只需将mybatis全局配置文件中更改运行字符编码把UTF-8改为GDK;
    在这里插入图片描述

  3. 报错四:
    Error building SqlSession.
    The error may exist in spring/wmm/mapper/StudentMapper.xml
    #Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource spring/wmm/mapper/StudentMapper.xml

    出现这种异常说明我们编写的.xml文件没有被maven加载进target文件中。
    补充target文件是干什么的:target文件夹是用来存放项目构建后的文件和目录、jar包、war包、编译的class文件,所有都是maven构建是生成的。
    出现之类问题我们只需在pom.xml文件中加人如下代码:
    !–src/main/resources下.properties和.xml文件无法被导出或者生效对的问题,–>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>
  1. 报错五
    ##Error building SqlSession.
    Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 16; 文档根元素 “configuration” 必须匹配 DOCTYPE 根 “null”。

    出现这种异常是因为mybatis全局配置中的头部配置缺少引发的
    在这里插入图片描述
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值