mybatis plus 出现 Invalid bound statement (not found)

mybatis-plus 3.5.6 has the following error according to the configuration of the official website

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.niu.manager.mapper.DepartmentMapper.selectList
at org.apache.ibatis.binding.MapperMethodKaTeX parse error: Undefined control sequence: \[ at position 43: …hod.java:235) ~\̲[̲mybatis-3.5.6.j…cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.6.jar:3.5.6]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_211]

solve

usual solution

  • Check configuration @MapperScan(basePackages = " com.xxx.mapper ")

  • Check if the configuration path of mybatis.mapper-locations: classpath: mapper/*.xml is correct

  • Pay attention to whether there is a mapper.xml file in the target directory of the project, if not, add the following configuration to pom.xml

    <!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
    

pit of mybatis puls

  • Pit: You cannot use the built-in SqlSessionFactory when using mybatis-plus. To use MybatisSqlSessionFactory, add the following configuration (springboot) to the configuration class

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

Guess you like

Origin blog.csdn.net/m0_54853503/article/details/123987242