问题1
有个xml文件的类型与其mapper名不一致,
调用接口时,提示
Invalid bound statement (not found)
问题2
MbgOrderDao.java 与MbgOrderDao.xml
xml的存放路径与Dao的包路径不一致
调用接口时,提示
Invalid bound statement (not found)
谜底
测试环境(一直没有问题)
application.yml中配置了
mybatis:
mapper-locations:
- classpath:dao/*.xml
- classpath*:com/**/mapper/**/*.xml
application-dev.yml
mybatis:
mapper-locations:
classpath: dao/*Dao.xml
正式环境(MbgOrderDao报Invalid bound statement (not found) )
application.yml中配置了
mybatis:
mapper-locations:
- classpath:dao/*.xml
- classpath*:com/**/mapper/**/*.xml
application-prod.yml
mybatis:
mapper-locations:
classpath:dao/*Dao.xml
知识点1:application-{profile}.yml中的配置会覆盖调application.yml中的同名key的配置
application-dev.yml中的mybatis:mapper-locations: 的值带空格,覆盖了application.yml的中mybatis:mapper-locations:
application-prod.yml中的mybatis:mapper-locations: 的值不带空格,没有覆盖覆盖了application.yml的配置classpath
知识点2:mybatis默认到报名的路径下找与mapper同名的xml文件,且springboot的resource的路径与mapper的报名一致时,编译后mapper与xml会在统一同一路径下,此时不配置xml扫描路径也可以
知识点3:
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印sql 返回值 也可打印扫描的xml文件,但是xml与mapper同路径时且未配置此处扫描路径,则不打印()
知识点4:答应mybatis读取的配置
public class Application implements CommandLineRunner{
@Autowired
MybatisProperties mybatisProperties;
public static void main(String[] args) {
SpringApplication.run(MallPortalApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
String[] argss = mybatisProperties.getMapperLocations();
System.out.printf(StringUtils.join(argss));
}
}