mybaits报错 Invalid bound statement

idea的maven+ssm–Invalid bound statement (not found)

Invalid bound statement 无效的绑定解决办法!!

错误如图:
在这里插入图片描述

在我的项目中,出现该错误是由于没找到Mapper映射文件(查看打包后的文件里面有没有对应的mapper.xml文件,如果没有则加入下面一段)。所以无法识别sql语句。

解决方法:
在pom配置文件中,在节点中加入以下代码:

<resources>
      <resource>
        <directory>src/main/java</directory>
        <!-- 此配置不可缺,否则mybatis的Mapper.xml将会丢失 -->
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <!--指定资源的位置-->
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>

Mapper映射文件其他错误原因:

在mapper代理开发中,程序员要遵守的接口规范,否则报错
1 mapper.xml中namespace要写映射的全名称如:com. china.xxx
2.每个statement的id要和接口方法的方法名相同:statement即是如:select、update等。
3.每个sql的parameterType要和接口方法的形参类型相同
4.每个sql的resultType要和接口方法的返回值的类型相同
5.A.mapper.xml要和对应的mapper接口在同一个包下;B.mapper.xml在resources包下(不在同一包),在mybaits配置文件中配置mybatis.mapper-locations = - classpath:mybatis/mapper/**/*.xml(指定的文件夹这里只是范例)
6.mapper.xml的命名规范遵守: 接口名+Mapper.xml

猜你喜欢

转载自blog.csdn.net/weixin_43118891/article/details/84350635
今日推荐