[Original] oop programming ibatis learning notes four-table join query expression

Source: Internet
Author: User

The classes of the two tables are shown in the previous article.<2Table join queries>

Here we will discuss how to use our habits.Inner joinOfSQLStatement to associate our data tables

 

The only difference is that

Book. xml

 

< Resultmap ID = "Get-book-Note" Class = "Com. It. Book" Groupby = "Book. oid" >
< Result Property = "Oid" Column = "Oid" />
< Result Property = "Name" Column = "Name" />
< Result Property = "Notes" Resultmap = "Get-Note"   />
</ Resultmap >

< Resultmap ID = "Get-Note" Class = "NOTE" >
< Result Property = "Sid" Column = "Sid"   />
< Result Property = "Sname" Column = "Sname"   />
</ Resultmap >

<SelectID= "Getproduct"Resultmap= "Get-book-Note">
 <! [CDATA [ 

Select

Book. OID,

Book. Name,

Note. Sid,

Note. sname

From

Book, note where note. book_oid = book. OID

 ]> 
</Select>

 

Notes: 1. SQLAll fields in the statement,All must be inResultmapEmbodied in,Otherwise, the queried fields areNULL;

2.Parent table associated with child table,Add

<Result Property="Notes" Resultmap="Get-Note" />

property Notes attributes and methods to obtain subclasses , the result must be a subclass resultmap id

3. SelectStatementResultmapCorresponds toResultmapName

 

Test statement'Main. Java

 

// Test the association between two tables. Author: meetweb Try {
Book book1 = New Book ();
Book1.setoid (1 );
List <book> books = sqlmapclinet. queryforlist ("getproduct ");
System. Out. println (books. Size ());
For (Iterator = books. iterator (); iterator. hasnext ();){
Book bookk = (book) iterator. Next ();
System. Out. println (bookk. getname ());
List <Note> L = bookk. getnotes ();
System. Out. println (Note) L. Get (0). getsname ());
}
} Catch (Sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}

Original Works. For reprinted works, please indicate the author.

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.