Mybatis Collection Query collection only one piece of data appears

Source: Internet
Author: User

Mybatis Collection Query collection only one piece of data appears 1. Reason

If two tables are checked, the primary key of the main table and the schedule is the ID, then the list can only query the first one.

2. Solutions

When cascading queries, the command query on MySQL is no problem when the primary table has the same field name as the table. However, in MyBatis, the master-slave table needs to set aliases for the same field name. Setting an alias is OK.

Example:

Main Table standard, from table standentity, fields that are known as IDs

<ResultmapID= "Standardandentityresultmap"type= "Whu.edu.irlab.model.Standard"extends= "Baseresultmap">    <Collection Property= "Standentities"OfType= "Whu.edu.irlab.model.StandEntity">(rename the field ID alias se_id According to the following select, where the same field name is changed to alias)<IDcolumn= "se_id" Property= "id"Jdbctype= "INTEGER" />         <resultcolumn= "stand_id" Property= "Standid"Jdbctype= "INTEGER" />        <resultcolumn= "Stand_name" Property= "Standname"Jdbctype= "VARCHAR" />        <resultcolumn= "Entity_name" Property= "EntityName"Jdbctype= "VARCHAR" />    </Collection></Resultmap> <SelectID= "Findallstandardandentity"Resultmap= "Standardandentityresultmap">Select standard.*, Standard_entity.id se_id, (where the same field name ID in both tables is changed to alias se_id, the corresponding collection section also needs to be changed) standard_ent ity.stand_id, Standard_entity.stand_name, standard_entity.entity_name from standard INNER JOIN Standard_enti Ty on standard.id = standard_entity.stand_id</Select>

Original link HTTP://MY.OSCHINA.NET/U/1020238/BLOG/517115?FROMERR=QPBX9VFC

Mybatis Collection Query collection only one piece of data appears

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.