SQL mapping File

Source: Internet
Author: User

1.SQL map file (..... Mapper.xml)

Several top-level elements of the SQL mapping file (in order of definition)

mapper-only one property namespace (namespace)

      Used to differentiate between different mapper, globally unique

Binding DAO interfaces, and interface-oriented programming

cache-Configuring the cache for a given namespace

cache-ref-applying cache configuration from other namespaces

Resultmap-used to describe the correspondence between a database result set and an object

Sql-can be reused for SQL blocks or referenced by other statements

insert-Mapping INSERT statement

update-Map UPDATE statement

delete-Map DELETE Statements

select-Mapping Query statements

mappings for the return result type of a select of a 2.SQL map file can use Resultmap and resulttype, but cannot be used at the same time.

Resulttype directly indicates that the return type includes the underlying data type and the complex data type.

Resultmap is a reference to an external RESULTMAP definition, an ID to an external resultmap that represents the Resultmap on which the returned results are mapped

Its application scenario is that database field information is inconsistent with object properties or complex joint queries are required to freely control the mapping results.

3. For MyBatis SQL statement parameter parameters, use @param annotations for parameter data of the underlying data type, and parameters for complex data types directly into the parameter.

The Association and collection of 4.RESULTMAP enable advanced result mapping.

The Association properties are:

    • Javatype: Full Java class name or alias. If mapped to a javabean, the MyBatis usually detects its own type;

   If you map to a hashmap, you should explicitly specify javatype to ensure the desired behavior.

    • Property: The attribute of the entity object that maps the database column.

The child elements of the association are:

    • Id
    • Result

Property: The attribute of the entity object that maps the database column.

Column: Database columns name or alias

The properties of the collection are:

    • OfType: The full Java class name or alias, and the type that the collection contains.
    • Property: The attribute of the entity object that maps the database column.   

5.MyBatis Cache

    • First-level cache: is based on the Perpetualcache (mybatis) HashMap local cache, scoped to the session field, but after the session flush or close, all the caches in the session are emptied.
    • Secondary cache: Is the global caching, it is outside the session range, can be shared by all sqlsession, open it only need to set in MyBatis core configuration file (Mybatis-config.xml) settings
    • The first-level cache caches the SQL statements, and the two-level cache caches the result objects.

SQL mapping File

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.