出现 Invalid bound statement (not found) 异常
之前一直用的 mybatis-plus 的框架,通过 QueryWrapper 进行查询操作。
今天,由于项目需要,要建立一个查询页面,数据来自 4 张表的联合查询,为此设计了相关的 VO,定制了相关的查询方法。运行的时候就出现了如题所示的问题,然后就一通排查。
显示排查引的包是不是正确,需要加的配置是否添加了等等。
我的项目结构是这样子的:
最后发现了问题并解决了,直接上答案。
问题的根本原因就是没找到 xml 文件。
# demo-web pom.xml# demo-worker pom.xml <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> <resource> <directory>../demo-dao/src/main/resources</directory> <includes> <include>mapper/*.xml</include> </includes> </resource> </resources># demo-config MyBatisPusConfig.java# sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*Mapper.xml")); @Bean(name = "SqlSessionFactory") public SqlSessionFactory test1SqlSessionFactory() throws Exception { //配置mybatis,对应mybatis-config.xml MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean(); //懒加载 LazyConnectionDataSourceProxy p=new LazyConnectionDataSourceProxy(); p.setTargetDataSource(dataSource(master(),slave())); sqlSessionFactory.setDataSource(p); sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources("classpath:/mapper/*Mapper.xml")); //需要mapper文件时加入扫描, // sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*/*Mapper.xml")); MybatisConfiguration configuration = new MybatisConfiguration(); configuration.setJdbcTypeForNull(JdbcType.NULL); configuration.setMapUnderscoreToCamelCase(true); configuration.setUseGeneratedKeys(true); configuration.setCacheEnabled(false); sqlSessionFactory.setConfiguration(configuration);
//加入上面的两个拦截器 Interceptor[] interceptor ={paginationInterceptor(),dynamicDataSourceInterceptor()}; sqlSessionFactory.setPlugins(interceptor); return sqlSessionFactory.getObject(); }#
复制代码
立贴为证,填坑记录。
评论