MyBatis Mapper Scan Path Guide
In MyBatis, you can specify the scan path for Mapper interfaces through a configuration file. The specific configuration method is as follows:
- the XML file for mybatis configuration
- cartographers
<configuration>
<!-- 其他配置 -->
<mappers>
<!-- 配置 Mapper 接口的扫描路径 -->
<package name="com.example.mapper" />
</mappers>
</configuration>
- In the
tag, use the name attribute to specify the package path where the Mapper interface is located. Wildcard * can be used to match multiple package paths. For example, if the Mapper interface is in the com.example.mapper package, it can be configured as . - Please note that MyBatis will by default scan XML configuration files with the same name as the Mapper interface, automatically binding them together. So, make sure that the Mapper interface and its corresponding XML configuration file have the same name, and are in the same package path.
In this way, when MyBatis is started, it will automatically scan the specified Mapper interface path and register it in MyBatis configuration for later use.