mybatis plus 常见问题Invalid bound statement (not found)解决方法汇总

中招第六点

before

    @Bean(name = "secondarySqlSessionFactory")
    public SqlSessionFactory secondarySqlSessionFactory(@Qualifier("secondaryDataSource") DataSource dataSource)
            throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        Interceptor[] plugins = new Interceptor[]{new PageHelper()};
        bean.setPlugins(plugins);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mappers/maxus/*.xml"));
        return bean.getObject();
    }

after 

  @Bean(name = "xdapSqlSessionFactory")
    public SqlSessionFactory xdapSqlSessionFactory(@Qualifier("xdapDataSource") DataSource dataSource)
            throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        //SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        Interceptor[] plugins = new Interceptor[]{new PageHelper()};
        bean.setPlugins(plugins);
        List<String> mapperLocations = new ArrayList<>();
        mapperLocations.add("classpath:mybatis/mappers/xdap/*.xml");
        Resource[] resources = resolveMapperLocations(mapperLocations);
        bean.setMapperLocations(resources);
        return bean.getObject();
    }


mybatis plus 常见问题Invalid bound statement (not found)解决方法汇总
一、问题描述
出现 Invalid bound statement (not found) 异常。

二、解决方法汇总
检查xml的namespace是否和xml文件的package名称一一对应;
检查xml中是否使用了type别名,如果用了别名,检查下别名包名是否配置正确,如果不确定,可以将实体类全包名加上去,还有就是看下实体类里面是否使用了typeHandler类型处理器,如果使用了,记得将完整包名加上去;
3.xxxMapper.java的方法返回值是List,而select元素没有正确配置ResultMap,或者只配置ResultType;
4.Mapper.xml不存在,一般mapper.xml会放在源码目录下,或resources目录下,检查mapper.xml打包后,在target/classes目录下是否存在;
注意mybatis/mybatis plus配置与@MapperScan 注解;
检查是不是引入 jar 冲突 如 mybtatis-plus springboot可以使用引入
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

如果以上还没有解决查看 mybatis-plus的SqlSessionFactory不要使用原生的,请使用MybatisSqlSessionFactory。如下
    @Bean(name = "sqlSessionFactory")
     @Primary
       public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource datasource)
          throws Exception {
               MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
              bean.setDataSource(datasource);
             bean.setPlugins(mybatisPlusInterceptor());
              System.out.println("bean = " + bean.toString());
              return bean.getObject();
   }

最后请查看mapper.xml的名称与mapper.java名称是否一致。

————————————————
版权声明:本文为CSDN博主「侯大」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhicong1652/article/details/127475671

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值