• springboot报错invalid bound statement (not found)


    1,概述

    springboot启动web项目后报错,

    invalid bound statement (not found):xxx

    2,问题分析

    这是很常见的一种异常,报错的情况通常有以下几种情况:

    2.1 语法错误

    mapper.xml与dao没有正确对应

     java DAO接口

    public void delete(@Param("id") String id);

    java对应的mapper.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="xxx.xxx.xxx.xxDao">
        <!-- 删除数据 -->
        <delete id="delete" parameterType="java.lang.String">
            DELETE FROM xxx WHERE id=#{id}
        </delete>
    </mapper>

    检查确认:

    a) 接口方法名称delete和xml中id=“delete”是否一致;

    b) xml文件中namespace="xxx.xxx.xxx.xxDao"是否和接口文件路径一致(点击能否跳转到对应的接口类);

    c) parameterType和resultType(resultMap)是否准确;

    2.2 编译错误

    检查项目 targetclasses路径下是否存在对应的mapper.xml文件

    若不存在则在pom.xml中添加

    <build>
        <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>
                <excludes>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.xml</exclude>
                </excludes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

    重新编译,则出现对应的xml文件(希望把src/main/java下的xml,properties等配置文件,复制到classes目录中,则加入如上配置);

     2.3  配置错误

    在配置文件中指定扫描包(mybatis.mapper-locations=classpath*:/xx/xx/mapper/*.xml)时,配置路径有问题。

    参考:

    https://www.cnblogs.com/momoweiduan/p/9844069.html

  • 相关阅读:
    解决pip3的ImportError: cannot import name 'main'
    linux 安装Python3.6
    Linux安装redis和部署
    redis密码管理
    CentOS7使用firewalld打开关闭防火墙与端口
    scrapy 从Windwos平台移植到 Linux平台之实操
    Linux 环境下安装Maven
    解决:安装Jenkins时web界面出现该jenkins实例似乎已离线
    持续集成工具Jenkins结合SVN的安装和使用
    Linux下的SVN服务器搭建
  • 原文地址:https://www.cnblogs.com/gezp/p/11996523.html
Copyright © 2020-2023  润新知