<!--the SQL mapping file (employeemapper.xml) that we have written must be registered with the global configuration file (Mybatis-config.xml)--
<!--6, mappers: Register the SQL map with the global configuration--
<mappers>
<!--
Mapper: Registering a SQL map
Registering a configuration file
Resource: Referencing the SQL mapping file under the Classpath
Mybatis/mapper/employeemapper.xml
URL: A reference to a network path or a SQL mapping file under a disk path
File:///var/mappers/AuthorMapper.xml
<!--<mapper resource= "Mybatis/mapper/employeemapper.xml"/>--
<!--<mapper url= "File:///var/mappers/AuthorMapper.xml"/>--
Register interface
Class: Reference (Registration) interface,
1, there is a SQL mapping file, the mapping file name must be the same name as the interface, and placed in the same directory as the interface;
2, there is no SQL mapping file, all SQL is written on the interface with annotations;
Recommended:
More important, complex DAO interfaces we write SQL mapping files
unimportant, simple DAO interface in order to develop fast can use annotations;
-
<!--<mapper resource= "Mybatis/mapper/employeemapper.xml"/>--
<!--<mapper class= "Com.atguigu.mybatis.dao.EmployeeMapperAnnotation"/>--
Note here that the DAO interface should start with the entity name
Public interface Employeemapperannotation {
@Select ("select * from Tbl_employee where Id=#{id}")
Public Employee Getempbyid (Integer ID);
}
<!--Bulk Registration:-
<package name= "Com.atguigu.mybatis.dao"/>
</mappers>
Mappers: Registering SQL Mappings in the global configuration