您的位置:首页 > 运维架构 > Apache

maven请求报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

2017-09-11 14:35 483 查看
参考:

博主1:http://blog.csdn.net/ppppfly/article/details/46847299

博主2:http://www.cnblogs.com/machanghai/p/5456294.html

背景:

maven+SSM项目,请求到dao层报错。

解释:

请求到dao方法后,在Mapper.xml中没有对用的映射;

原因:

博主1写的非常详细,本人稍加更改了下解决方法,我的是第六种:

1、mapper接口和mapper.xml是否在同一个包(package)下?名字是否一样(仅后缀不同)?mapper.xml可以在子包下面,但是配置的时候路径要正确

2、mapper.xml的命名空间(namespace)是否跟mapper接口的包名一致?

比如,你接口的包名是com.abc.dao,接口名是NameMapper.java,那么你的mapper.xml的namespace应该是com.abc.dao.NameMapper

3、接口的方法名,与xml中的一条sql标签的id一致

4、如果接口中的返回值List集合(不知道其他集合也是),那么xml里面的配置,尽量用resultMap(保证resultMap配置正确),不要用resultType

5、如果你的项目是maven项目,请你在编译后,到接口所在目录看一看,很有可能是没有生产对应的xml文件,因为maven默认是不编译的,因此,你需要在你的pom.xml的<build></build>里面,加这么一段:

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

我查看了下确实没有编译出这个文件,但是在我的项目中之家这一句还是没作用的,因为maven的项目在java同级的还有sources资源文件夹,这个也要加上,我加的是

<!-- 解决不编译java下的mybatis映射文件.xml文件 -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<!-- 解决不编译resources下的配置文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
但是本人竟然是第六种:

就是这个mapper.xml在子包下的时候路径没配置对,应该是

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/sosoyo/jzy/dao/mapper/*.xml"></property>
</bean>

我写成了    value="classpath:com.sosoyo.jzy.dao.mapper.*.xml"

所以,注意点啊少年,java中配置对了,你就成功了99%,那一乘就靠手撸吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven
相关文章推荐