mybatis plus 报错 Invalid bound statement (not found)

Error message: Invalid bound statement (not found)

Reason: When using mybatis-plus, you cannot use the built-in SqlSessionFactory. You must use MybatisSqlSessionFactory . MybatisSqlSessionFactory will proxy these commonly used methods for adding, deleting, checking, and modifying.

Solution: Add the following configuration code.

    @Primary
    @Bean("db1SqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
        //使用 mybatis plus 配置
        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
        mybatisSqlSessionFactoryBean.setDataSource(dataSource);
        mybatisSqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
        return mybatisSqlSessionFactoryBean.getObject();
    }

Note that the classpath:mapper/*.xml path must be consistent with your actual mapper.xml file path, here is the mapper folder in the resources directory.

 

Guess you like

Origin blog.csdn.net/zdb1314/article/details/124286025