MyBatis(3.2.3) - Configuring MyBatis using XML, Mappers

时间:2021-02-20 21:19:09

Mapper XML files contain the mapped SQL statements that will be executed by the application using statement id. We need to configure the locations of the SQL Mapper files in mybatis-config.xml.

<mappers>
<mapper resource="com/mybatis3/mappers/StudentMapper.xml"/>
<mapper url="file:///D:/mybatisdemo/app/mappers/TutorMapper.xml"/>
<mapper class="com.mybatis3.mappers.TutorMapper"/>
<package name="com.mybatis3.mappers"/>
</mappers>

Each of the <mapper> tag attributes facilitates to load mappers from different kinds of sources:

  • The attribute resource can be used to point to a mapper file that is in the classpath
  • The attribute url can be used to point to a mapper file by its fully qualified filesystem path or web URL
  • The attribute class can be used to point to a Mapper interface
  • The package element can be used to point to a package name where Mapperinterfaces can be found