Mybatis的xml文件扫描之填坑

问题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));

    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatisXML文件是用来配置MyBatis框架的行为和映射关系的文件。在XML文件中,可以配置数据源、映射器和类型处理器等。 为了让MyBatis查找类型处理器,可以在mybatis-config.xml文件中添加typeHandlers元素,并指定要扫描的包名,如下所示: ```xml <!-- mybatis-config.xml --> <typeHandlers> <package name="org.mybatis.example"/> </typeHandlers> ``` 这样,MyBatis扫描指定包下的所有类,并将其注册为类型处理器。 如果想要显式地配置类型处理器,可以在typeHandlers元素中添加typeHandler元素,并指定要使用的处理器类,如下所示: ```xml <!-- mybatis-config.xml --> <typeHandlers> <typeHandler handler="org.mybatis.example.ExampleTypeHandler"/> </typeHandlers> ``` 这样,MyBatis会将ExampleTypeHandler类注册为类型处理器。 另外,如果想要在XML文件中配置插件,可以在plugins元素中添加plugin元素,并指定要使用的拦截器类,如下所示: ```xml <!-- mybatis-config.xml --> <plugins> <plugin interceptor="org.mybatis.example.ExamplePlugin"> <property name="someProperty" value="100"/> </plugin> </plugins> ``` 这样,MyBatis会将ExamplePlugin类注册为插件,并将属性配置为指定的值。 通过配置MyBatisXML文件,可以灵活地配置和扩展MyBatis框架的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [MyBatis xml配置文件详解](https://blog.csdn.net/guorui_java/article/details/109106704)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [MyBatis——详解XML配置文件](https://blog.csdn.net/Huang_ZX_259/article/details/121579618)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值