MybatisPlus使用过程的Invalid bound statement (not found)问题

一 概述

该文章记录本人使用MybatisPlus时踩过的坑。

二 Invalid bound statement (not found)问题的解决

分析过程:大概率是扫包时没有找到文件

1. 首先判断是否在springboot启动类上有相应配置或者是在项目中存在相应的配置类。

@SpringBootApplication
@ComponentScan(basePackages = {"com.zero.zookeeperconfig", "com.zero"})
@MapperScan( basePackages = "com.zero.web.mapper")
@EnableScheduling
public class PrintWebApplication {

    public static void main(String[] args) {
        SpringApplication.run(PrintWebApplication.class, args);
    }
}

2. 接着查看mapper.xml中的namespace与使用的实际类是否一致。

<?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="com.zero..mapper.BusinessCompoundPageMapper">

    <select id="compoundPageGoods" parameterType="integer" resultType="com.zero.vo.business.coupoundpage.CompoundPageGoodsVO">
        SELECT s.id AS send_config_id, s.coupon_id AS couponId, c.`name` AS coupon_name, g.`name` AS goods_name,c.create_time,s.compound_page_show_flag, s.sort
        FROM print_coupon c
            INNER JOIN (
            SELECT id, coupon_id, compound_page_show_flag, sort, create_time
            FROM print_coupon_send_config
            WHERE channel_id = #{channelId}
            AND del_flag = 0
        ) s
        ON s.coupon_id = c.id
            LEFT JOIN (
            SELECT id, `name`
            FROM print_goods
            WHERE del_flag = 0
        ) g
        ON c.good_id = g.id
        WHERE c.del_flag = 0
        ORDER BY c.create_time ASC;
    </select>
</mapper>

3. 当namespace一致时,接着查看mapper.xml中的标签id是否同mapper接口方法名是否一致。

public interface PrintBusinessCompoundPageMapper extends BaseMapper<PrintBusinessCompoundPageEntity> {

    List<CompoundPageGoodsVO>  compoundPageGoods(@Param(value = "channelId") Integer channelId);
}

4. 实际上一般都是这些原因造成,当时在自己编写mapper接口和对应的mapper.xml文件的时候,应该保证两个文件的文件名相同,否者会报Invalid bound statement (not found)的问题。

经过上述的分析过程,还是没有解决该问题,最后我作了一个猜测,因为我是将mapper接口文件和对应的mapper.xml放在不同目录下,可能是这个原因,所以我将他们放在同一个目录下,最后问题解决了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值