Mapper Dynamic Agent Considerations

Source: Internet
Author: User

Mapper excuse similar to DAO connector

The MyBatis framework creates an interface's dynamic proxy object based on the interface definition

Mapper interface development needs to follow 4 development specifications

The namesapce of the mapping file in mapper is the same as the classpath of the Mapper interface

The Mapper interface method name and the ID of each SQL defined in the Mapper mapping file are the same

The input parameter type of the Mapper interface method is the same as the type of paramenttype defined for each SQL in the mapper mapping file

The output parameter type of the Mapper interface method is the same as that of each SQL-defined Resulttype in the mapper mapping file

Mapper mapping file Usermapper.xml placed in the Mapper directory of resources

<?xml version="1.0"encoding="UTF-8"? ><!DOCTYPE mapperpublic"-//mybatis.org//dtd Mapper 3.0//en""HTTP://MYBATIS.ORG/DTD/MYBATIS-3-MAPPER.DTD"><!--namespace: namespaces, which are used to isolate SQL--><!--also has an important role in developing DAO with dynamic agents,1. The namespace must be consistent with the Mapper interface class path--><mappernamespace="Com.itheima.mybatis.mapper.UserMapper"> <!--query users by User ID--<!--2. The ID must match the Mapper interface method name-<!--3. The parametertype must be consistent with the interface method parameter type-<!--4. Resulttype must be consistent with the interface method return value type-<SelectId="Queryuserbyid"Parametertype="Integer"Resulttype="Com.itheima.mybatis.pojo.User">Select* fromUserwhereID =#{id}</Select></mapper>

Mapper Dynamic Agent Considerations

Related Article

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.