出现异常:
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
重启项目,解决。