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();
    }


}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM