0
点赞
收藏
分享

微信扫一扫

Spring整合mybatis遇到的坑

村里搬砖的月野兔 2022-01-09 阅读 78

Spring整合mybatis遇到的坑


mybatis-spring整合包【重点】
mybatis:使用3.5+的; mybatis-spring就必须使用 2.0+的 ; spring:5.0+ ; Java:8+
mybatis:使用3.4+的; mybatis-spring就必须使用 1.3+的 ; spring:3.2.2+ ; Java:6+

在这里插入图片描述
异常1.

org.apache.ibatis.binding.BindingException: Type interface com.hh.mapper.UserMapper is not known to the MapperRegistry.

在这里插入图片描述
接口UserMapper 没有登记注册进MapperRegistry
解决(在核心配置文件mybatis-config.xml中添加上)

<mappers>
     <mapper class="com.hh.mapper.UserMapper"/>
</mappers>

异常2 :

 java.io.IOException: Could not find resource mybatis-config.xml

找不到核心配置文件
解决:(在pom.xml中添加在build时要扫描的包以及文件的后缀)

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

异常3:

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'deletes from mybatis.user where id=5' at line 1

这个异常指的是SQL语句错误,自己去检查一下SQL语句是否出错,可以单独把语句放到数据库工具中测试(SQLyog或者navicat

举报

相关推荐

0 条评论