Mappers: Registering SQL Mappings in the global configuration

Source: Internet
Author: User

<!--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.