Configuring MyBatis Mapper Paths

In the configuration file of MyBatis, you can use the element to configure the path of the Mapper interface.

  1. Configuration file for MyBatis: mybatis-config.xml
  2. cartographers
<configuration>
   ...
   <mappers>
      <!-- 配置 Mapper 接口的路径 -->
      <mapper resource="com/example/mappers/ExampleMapper.xml"/>
      <mapper class="com.example.mappers.AnotherMapper"/>
      <package name="com.example.mappers"/>
   </mappers>
   ...
</configuration>
  1. – the one who selects or assigns tasks or responsibilities.
  1. Specify the path of the Mapper XML file using the resource property, for example .
  2. Specify the fully qualified name of the Mapper interface using the class attribute, for example .
  3. The “package” element is used to specify a package, and MyBatis will automatically scan all Mapper interfaces in that package, for example .

Note: It is possible to use resource, class, and package to configure the path of the Mapper interface.

After this configuration, MyBatis will automatically scan and load the corresponding Mapper interfaces based on the configured path.

bannerAds