zoukankan      html  css  js  c++  java
  • org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    出现异常:

    AbstractHandlerExceptionResolver.java:194 |org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver |Resolved exception caused by handler execution: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.online.edu.mapper.CourseMapper.getCoursePublishVoById

    分析问题

    经过查找与判断不是SQL语句的问题,而是配置文件没有加载到。

    dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所有资源文件是不发布到target目录下的,只有resources目录下的配置文件可以被编译到class中。

    解决方案

    第一种

    手动改变项目文件结构,也就是将mapper目录下的xml文件放到resources目录下。但是这种改变项目结构的方法不推荐。

    第二种

    在该项目的pom.xml文件中添加以下配置。

    <!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
    

    同时在application.properties/application.yml中添加mapper下xml文件的扫描路径。

    #配置mapper xml文件的路径
    mybatis-plus.mapper-locations=classpath:com/online/edu/mapper/xml/*.xml
    

    重启项目,解决。

  • 相关阅读:
    测试发帖
    C# 四舍五入算法(转)
    赚钱,爱好,生活
    c# 当前dll目录
    BlogWriter
    调用com+时,提示 0x800706f7,error msg:占位程序接收到错误数据,(本地调用时提示:不支持此接口)
    测试2
    系统架构设计 & 避免循环引用(转载)
    Visual Studio 2008查找替换用的正则
    Myeclipse webinf/lib包加载问题
  • 原文地址:https://www.cnblogs.com/dataoblogs/p/14121836.html
Copyright © 2011-2022 走看看