Mybatis-Plus报Invalid bound statement (not found)

Mybatis-Plus报Invalid bound statement (not found) 常见的错误原因

1,xml中的 namespace 标签

<mapper namespace="com.demo.dao.DemoJavaMapper">

确认这个路径可以找到JAVA类文件,正确的路径

2,确认Mapper类的方法和xml文件中的方法名称,参数列表相同,返回类型相同

 <select id="selectByNameAndSex" resultMap="BaseResultMap">
DemoJava selectByNameAndSex(@Param("name") String name,@Param("sex") String sex);

3,是否重复扫描,启动类和数据源配置 类扫描重复

@SpringBootApplication
@MapperScan(basePackages="com.demo.dao")
@EnableScheduling
public class SpringBootApplication{


}
@MapperScan(basePackages = "com.demo.dao")
public class DataSourceConfig {

}

4,JAVA类是否有标明主键,使用注解  @TableId

@Data
public class DemoJava implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
}

5,SqlSessionFactory不要使用原生的,请使用MybatisSqlSessionFactor

@MapperScan(basePackages = "com.demo.dao")
public class DataSourceConfig {
    @Bean(name = "sqlSessionFactory")
    @Primary
    public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource datasource)
            throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        bean.setDataSource(datasource);
        bean.setMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml"));
        return bean.getObject();
    }


}

posted @ 2022-03-14 19:06  明晓默  阅读(1574)  评论(0编辑  收藏  举报