I. tasks that developers need to accomplish:
Mapper.xml mapping files and Mapper.java
two. Development Specifications
1, namespace equals mapper interface address in Mapper.xml.
2. The method name in the Mapper.java interface is consistent with the statement ID in the Mapper.xml
3. The method input parameter type in the Mapper.java interface is consistent with the type of parametertype specified in the Mapper.xml statement .
4. methods in the Mapper.java interface return value types and statement resulttype in Mapper.xml Specifies the same type.
Mapper.java Example
Query user information according to ID public finduserbyid (int id) throws Exception;
Mapper.xml Example
<select id= "Finduserbyid" parametertype= "int" resulttype= "user" >select * from user WHERE Id=#{value}</select >
5. load the mapper.xml in sqlmapconfig.xml
<!--loading a single mapping file via the Mapper interface follows some specifications: The Mapper interface class name and the Mapper.xml mapping file name need to be consistent, and the upper specification in one directory is the premise that the Mapper proxy method is used--><map Pers><mapper class= "Cn.itcast.mybatis.mapper.UserMapper"/></mappers>
Or
<mappers><!--Bulk Load mapper Specifies the package name of the Mapper interface, MyBatis automatically scans all mapper interfaces underneath the package follows some specifications: The Mapper interface class name and the Mapper.xml mapping file name need to be consistent, and the upper specification in one directory is based on the assumption that the Mapper proxy method is used-->< Package Name= "Cn.itcast.mybatis.mapper"/></mappers>
MyBatis study notes, use of Mapper proxy methods