[Java] [ibatis] difference in map result set obtained through resultmap and resultclass

Source: Internet
Author: User
Difference in map result set obtained through resultmap and resultclass

Alias ing-> entity class: resultclass
<Select id = "selectall" resultclass = "applog">
Select
ID as ID,
Type as type,
Descr as descr
From app_log
Where id = # ID #
</SELECT>
List list = sqlmapper. queryforlist ("selectall ");
For (INT I = 0; I <list. Size (); I ++ ){
Applog log = (applog) list. Get (I );
// Add your code here;
}

Alias ing-> map class: resultclass
<Select id = "selectall" resultclass = "Java. util. hashmap <string, string>">
Select
ID as ID,
Type as type,
Descr as descr
From app_log
Where id = # ID #
</SELECT>
List list = sqlmapper. queryforlist ("selectall ");
For (INT I = 0; I <list. Size (); I ++ ){
Map map = (MAP) list. Get (I );
String id = (string) map. Get ("ID ");
String type = (string) map. Get ("type ");
String descr = (string) map. Get ("descr ");
// Add your code here;
}

Explicit ing-> entity class: resultmap
<Resultmap id = "applogresult" class = "applog">
<Result property = "ID" column = "ID"/>
<Result property = "type" column = "type"/>
<Result property = "descr" column = "descr"/>
</Resultmap>

<Select id = "selectall" resultmap = "applogresult">
Select * From app_log
</SELECT>
List list = sqlmapper. queryforlist ("selectall ");
For (INT I = 0; I <list. Size (); I ++ ){
Applog log = (applog) list. Get (I );
// Add your code here;
}

Explicit ing-> map class: resultmap
<Resultmap id = "Map-result" class = "Java. util. hashmap">
<Result property = "ID" column = "ID"/>
<Result property = "type" column = "type"/>
<Result property = "descr" column = "descr"/>
</Resultmap>

<Select id = "selectall2" resultmap = "Map-result">
Select * From app_log
</SELECT>
List list = sqlmapper. queryforlist ("selectall2 ");
For (INT I = 0; I <list. Size (); I ++ ){
Map map = (MAP) list. Get (I );
String id = (string) map. Get ("ID ");
String type = (string) map. Get ("type ");
String descr = (string) map. Get ("descr ");
}

No ing
<Select id = "selectall3" resultclass = "Java. util. hashmap">
Select * From app_log
</SELECT>
List list = sqlmapper. queryforlist ("selectall3 ");
For (INT I = 0; I <list. Size (); I ++ ){
Map map = (MAP) list. Get (I );
String id = (string) map. Get ("ID ");
String type = (string) map. Get ("type ");
String descr = (string) map. Get ("descr ");
}

XML

<Select id = "selectxml" parameterclass = "Java. Lang. String" resultclass = "XML" xmlresultname = "log">
Select
ID as ID,
Type as type,
Descr as descr
From app_log
Where id = # ID #
</SELECT>
String o = (string) sqlmapper. queryforobject ("selectxml", ID );
System. Out. println (O );

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.