先展示错误
Invalid bound statement (not found): 可能的导致原因
1:mapper接口与 Mapper.xml文件中的namespace类路径相同。
2:mapper接口名称和Mapper.xml名称相同,且放在同一个目录中
3:Mapper接口方法名和Mapper.xml中定义的每个statement的id相同
4:去掉xml文件中的中文注释
5:随意在xml文件中加一个空格或者空行然后保存(触发idea自动编译)
6:配置扫描包,value匹配到mapper包
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.item.springmvc.mapper"/>
</bean>
一般来说到此就可以排除错误了
以上方法都解决不了
war包找不到mybatis中的Mapper.xml配置文件:
需要在pom.xml添加配置
<build>
<finalName>springmvc</finalName>
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
添加到pom.xml后,重启tomcat,就会加载到mapper.xml配置,运行正常!