mapper配置class映射报Exception in thread “main“ org.apache.ibatis.binding.BindingException: Invalid bound

问题:

在mybatis-config.xml文件里的<mappers></mappers>里配置class映射时,xml文件已和接口文件放在同一路径下,运行仍报错

 <!--class:映射单个文件 ,指定的接口文件要遵循指定规则:mapper.xml和mapper.java必须是同一路径下,且名称保持相同-->
        <mapper class="com.tulun.maventest.mapper.StudentMapper"/>

错误信息如下:
Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.tulun.maventest.mapper.StudentMapper.selectStudentById
at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:223)

在这里插入图片描述

原因:

java下的mapper文件里的接口对应的StudentMapper.xml文件并没有被加载
在这里插入图片描述

解决方案:

1.确保接口文件和其xml文件名字完全一致
在这里插入图片描述

2.在pom.xml文件里,找到<bulild></build>标签,给里面添加如下代码。作用是让编辑器去resources和java路径下去加载xml文件。只有先加载到了,才能去用指定位置的xml文件。

<resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.tld</include>
                <include>**/*.xls</include>
                <include>**/*.xlsx</include>
            </includes>
            <!--<filtering>true</filtering>-->
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.tld</include>
                <include>**/*.xls</include>
                <include>**/*.xlsx</include>
                <include>**/*.xml</include>
            </includes>
            <!--<filtering>true</filtering>-->
        </resource>
    </resources>

3.编辑完重新运行即可

参考资料:

idea maven项目src下文件没有同步到target

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值