MyBatis(3.2.3) - Configuring MyBatis using XML, Mappers

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

 

posted on 2016-02-29 16:15  huey2672  阅读(223)  评论(0编辑  收藏  举报