四、mybatis报错总结

一、导入mybatis文件mybatis-config.xml报红

IDEA中在编辑mybatis-config文件时候,http://mybatis.org/dtd/mybatis-3-config.dtd 报红
在这里插入图片描述
解决:
在这里插入图片描述

OK:👇🏾

在这里插入图片描述

二、Unable to import maven project: See logs for details

在这里插入图片描述
换个低版本的 maven ,比如 apache-maven-3.5.4 或者apache-maven-3.6.0-bin ,这里一般是 idea2019.1 与高版本的 maven (apache-maven-3.8.2 )不太兼容导致的。

三、绑定异常

(1) org.apache.ibatis.binding.BindingException: Type interface com.zql.dao.UserMapper is not known to the MapperRegistry.

在这里插入图片描述

解决 👇🏾:

在这里插入图片描述

当你的项目在eclipse中能正常运行,但是导入到IDEA中就会报如下错误:

(2)Connected to the target VM, address: ‘127.0.0.1:5263’, transport: ‘socket’
Disconnected from the target VM, address: ‘127.0.0.1:5263’, transport: ‘socket’
org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
The error may exist in com/glory/mapper/userMapper.xml
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/glory/mapper/userMapper.xml

在这里插入图片描述

解决: 在pom.xml导入资源过滤配置

<!-- 如果mapper.xml是放在src/main/resources目录下,需配置以下-->
<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>

四、java.lang.ExceptionInInitializerError

maven由于他的约定大于配置,导致无法导出或生效问题

4.1 第一种报错

在这里插入图片描述

4.2 第二种报错(java.io.IOException: Could not find resource mybatis-config.xml )

在这里插入图片描述

解决 👇🏾:

<!--在build中配置resources,来防止我们资源导出失败的问题-->
 <build>       
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>

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

五、set标签问题

org.apache.ibatis.exceptions.PersistenceException:

Error updating database. 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 'gprice = 9999.0

在这里插入图片描述
解决:set 标签中缺少逗号

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Daniel521-Spark

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值