Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

宜立方商城项目,整合测试,向服务器发送请求:localhost:8080/item/1,简单的业务逻辑测试,查询id=1的商品信息。发出请求后得到500错误。

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

出错原因:

mybatis的接口和映射文件不在同一个路径下面,服务器只找到了接口却没有找到映射文件(没找到实现类)。

在eclipse中一切显示正常:

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

但是在编译后的本地文件目录中却如如下截图,只找到接口类,却没有映射文件:

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

 

修改方法:

在dao层组件的pom文件最后加入如下节点:

 

 
  1. <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉 -->

  2. <build>

  3. <resources>

  4. <resource>

  5. <directory>src/main.java</directory>

  6. <includes>

  7. <include>**/*.properties</include>

  8. <include>**/*.xml</include>

  9. </includes>

  10. <filtering>false</filtering>

  11. </resource>

  12. </resources>

  13. </build>


修改pom文件后重新启动maven编译器,没有报错了,回到本地编译目录下发现映射文件和接口文件成功共存于一个目录:

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

 

再次向服务器发送请求:。。。请求id=1的商品失败,根本不存在这号商品,检查数据库重新查询:

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample

查询到商品信息,成功返回json数据:

Invalid bound statement (not found): cn.e3mall.mapper.TbItemMapper.selectByExample