MyBatis mapper-locations: Purpose & Configuration
In MyBatis, the mapper-locations property specifies the location of Mapper interface files.
Its purpose is to inform MyBatis where to search for Mapper interfaces in order to map them to corresponding SQL statements. MyBatis will load the corresponding Mapper interface files based on the value of the mapper-locations property and register them in MyBatis configuration.
The mapper-locations attribute can be used to specify one or more paths, which can be either file system paths or paths under the classpath. Wildcards can be used in the paths to match multiple files, such as classpath*:mappers/*.xml.
Example usage:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mappers/*.xml" />
</bean>
In the above example, the mapperLocations property is set to classpath:mappers/*.xml, which means that MyBatis will search for all files ending with .xml in the mappers directory under the classpath as Mapper interface files.
In summary, the purpose of the mapper-locations property is to inform MyBatis where to search for Mapper interface files and register them in MyBatis configuration for mapping SQL statements.