MyBatis study notes, use of Mapper proxy methods

Source: Internet
Author: User
Tags xml example

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

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.