SpringBoot+MyBatis报错Invalid bound statement (not found)

SpringBoot+MyBatis报错Invalid bound statement (not found)

首先我使用的开发工具是idea
Springboot的目录结构是
在这里插入图片描述
这里我就不一一介绍了,我的mapper层代码如下

@Mapper
@Repository
public interface StudentMapper extends BaseMapper<Student> {

    List<Map> execSQL(Page page);

    List<Map> getStudentList();
}

StudentMapper需要有两个注解为@Mapper和@Repository并且继承BaseMapper
下面定义的是自己想要的接口 首先我自己写了一个getStudentList()接口对应的xml文件如下:

StudentMapper.xml
namespace这里必须指向StudentMapper id对应方法名称getStudentList
检查: 1、 接口中方法名(getStudentList)与xml文件中 id="getStudentList"是否一致
   2、 xml文件中的 namespace=“xxx.xxx.xxx.Mapper” 中的路径是否与接口文件路径一致
   3、.parameterType类型 与 resultType类型是否准确;resultMap与resultType是不一样的。

<?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">
<!-- namespace必须指向mapper接口 -->
<mapper namespace="com.ccut.ebusiness.module.school.mapper.StudentMapper">

    <select id="execSQL" parameterType="com.ccut.ebusiness.module.tool.Page" resultType="map">
        ${exec_sql}
    </select>

    <select id="getStudentList" resultType="map">
        select * from student where deltag = '0' order by c_time desc
    </select>
</mapper>

在pom.xml 文件需要配置扫描xml包

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

mybaits所需的依赖包

		<!--baomidou-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatisplus-spring-boot-starter</artifactId>
            <version>1.0.5</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.0.1</version>
        </dependency>

        <!--Spring Boot Mybatis 依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>

最后再检查
applicatio.yml文件里面配置的mybaits扫描mapper包的路径是否正确

mybatis:
  mapper-locations: classpath*:mapper/*.xml
  type-aliases-package: com.ccut.ebusiness.module.school.entity

我报错的原因是由于少了一个依赖包导致的,其他部分都是上网对了很多遍一点问题都没有,而且自己在xml文件里写SQL语句能正常访问读取数据,但是用mapper里面的自带方法就会报错 Invalid bound statement (not found) 最终添加这个依赖包解决了

		<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatisplus-spring-boot-starter</artifactId>
            <version>1.0.5</version>
        </dependency>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值