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();
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通