測試:報告異常
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.guli.edu.mapper.CourseMapper.getCoursePublishVoById
問題分析:
dao層編譯后只有class文件,沒有mapper.xml,因為maven工程在默認情況下src/main/java目錄下的所有資源文件是不發布到target目錄下的,
解決方案:
出現這個錯誤時,按以下步驟檢查一般就會解決問題: 1:檢查xml文件所在package名稱是否和Mapper interface所在的包名一一對應; 2:檢查xml的namespace是否和xml文件的package名稱一一對應; 3:檢查方法名稱是否對應; 4:去除xml文件中的中文注釋; 5:隨意在xml文件中加一個空格或者空行然后保存。
1、在pom中配置如下節點
<!-- 項目打包時會將java目錄中的*.xml文件也進行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
重新打包項目會發現target目錄下出現了xml文件夾

2、在Spring Boot配置文件中添加配置
#配置mapper xml文件的路徑 mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml
