|
Result Mapping to HashMap
The following example shows using a result map.
It provides a way of mapping resultant columns with java hash map.
|
package com.bethecoder.tutorials.ibatis.tests.basic;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class MapResults {
/**
* @param args
* @throws IOException
* @throws SQLException
*/
public static void main(String[] args) throws IOException, SQLException {
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient(reader);
List<Map> studs = (List<Map>) sqlMapClent.queryForList("Student.getAllAsMap");
for (Map stud : studs) {
System.out.println(stud);
}
}
}
|
| |
It gives the following output,
{studentId=1, fullName=Jim Attic}
{studentId=2, fullName=Raj Kumar}
{studentId=3, fullName=Ram Prasad}
{studentId=4, fullName=Arjun Mishra}
{studentId=5, fullName=Vishal Pratap}
|
|