1. 程式人生 > >解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)...

解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)...

filter mapper lte exce 文件創建 state ibatis gen 目錄

在IDEA中將xxxMapper.xml文件創建在(src/main/java)目錄中,運行報錯:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):com.gentlehu.diary.mapper.TestMapper.findById(id);

意思是沒找到TestMapper的findById方法還有這個類的其他方法。

找了好久,發現在idea生成的classes中沒有DiaryMapper.xml文件。

原來在IDEA中目錄是普通屬性,所以它的(src/main/java)目錄中的只有.java文件會默認編譯,.xml文件不會被編譯。

而在MyEclipse中可以運行的,因為MyEclipse中建立的是目錄(src/main/java)的屬性是資源目錄,所以MyEclipse識別了這個屬性會自動把這個目錄的所有內容編譯生成在classes中。

所以需要在maven的pom.xml中配置一下節點

<project>
        ......
        <build>
            <resources>
        <resource>
            <directory>src/main/java</directory>
                <
includes> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> </resources> </build> </project>

然後IDEA才會編譯.xml文件。

解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)...