天天看點

mybatis系統學習10-xml配置-映射器(mappers)

3.9、映射器(mappers)

  1. 定義映射檔案在哪

方式1(不推薦)

<!--使用相對于類路徑的資源引用-->
<mappers>
    <mapper resource="day12/UserMapper.xml"/>
</mappers>
           
mybatis系統學習10-xml配置-映射器(mappers)

方式2(不推薦)

  1. 接口和他的Mapper配置檔案必須同名
  2. 接口和他的Mapper配置檔案必須在同一個檔案夾
mybatis系統學習10-xml配置-映射器(mappers)

方式3 (推薦)

  1. 接口和他的Mapper配置檔案必須同名
  2. 接口和他的Mapper配置檔案必須在同一個檔案夾
mybatis系統學習10-xml配置-映射器(mappers)

方式4

<!-- 使用完全限定資源定位符(URL) -->
<mappers>
    <mapper url="file:///D:\java\workSpace\git\mybatis-learn-master\src\main\resources\day12\UserMapper.xml"/>
</mappers>
           
mybatis系統學習10-xml配置-映射器(mappers)

代碼位址:https://gitee.com/DanShenGuiZu/learnDemo/tree/mysql_mybaties_DB/mybatis-learn-master

繼續閱讀