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