Invalid bound statement (not found): com.bookestore.dao.OrderInfoDao.findList的根本原因及解决方案

来源:互联网 发布:制作录音广告软件 编辑:程序博客网 时间:2024/05/23 01:59

Mybatis自定义xml多表查询教程:http://blog.csdn.net/a13432421434/article/details/78369650

描述:利用mybatis逆向工程可以生成单表的增删改查dao层,但能不能根据它的原理,自己去写一个xml来执行多表查询并返回结果呢?在好奇心的驱使下,自己亲自写了一个,其他配置基本没问题,但就是一直报这个错,弄了我两天,终于在一篇文章中找到真正的解决方案(在检查B步骤中),如果确信基本的配置是没问题的,可直接看最后面的检查B步骤;

目标描述编写一个xml执行sql语句,查询两个关联的表的不同属性的值,得到两个表综合字段的结果集,并返回




首先要保证你的xml以及dao接口的配置等等的正确性(最基本的,重要的是检查B步骤),下面所有标注红色字体的都是必须检查或注意的地方

检查A

1.利用mybatis逆向工程,applicationContext-mybatis.xml必须的bean配置,如下:





目录:



2.检查dao接口:



MyBatisDao.java(import的包都是mybatis里面的包)

/** * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. */package com.bookestore.dao;import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.springframework.stereotype.Component;/** * 标识MyBatis的DAO,方便{@link org.mybatis.spring.mapper.MapperScannerConfigurer}的扫描。  * @author thinkgem * @version 2013-8-28 */@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)@Documented@Componentpublic @interface MyBatisDao {/** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. * @return the suggested component name, if any */String value() default "";}



3.检查xml



若检查A都没配置错,那么久要检查以下步骤:


检查B:看看你的工程的pom.xml是否已经配置以下配置?若没有该配置,那么,你写的dao接口和xml就会被漏掉,也就是说,下面的配置就像一个媒婆,给工程介绍这是xml妹妹,没有媒婆,工程不认识茫茫人海的这个xml妹妹,所以就会报Invalid bound statement (not found):错误



<build><!-- 如果不添加此节点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>  </build>


注意:以上所有检查,都是本人的亲身经历,涵盖整个逆向工程的核心流程所得的体会,根据上面的配置,是完全可以自定义xml进行多表查询,若果你还是报其他错,那就请仔细看上面的流程的红色字体所表达的意义,这个必须都要明白。

天啊。。。。忽然想起来,,我的哇哈哈还没喝完呢,,,那我先去喝奶咯,各位拜拜。。


阅读全文
0 0
原创粉丝点击