Example usage for org.apache.ibatis.session SqlSession selectMap

List of usage examples for org.apache.ibatis.session SqlSession selectMap

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectMap.

Prototype

<K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey);

Source Link

Document

The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.

Usage

From source file:net.hasor.db.orm.mybatis3.SqlExecutorTemplate.java

License:Apache License

public <K, V> Map<K, V> selectMap(final String statement, final Object parameter, final String mapKey)
        throws SQLException {
    return this.execute(new SqlSessionCallback<Map<K, V>>() {
        public Map<K, V> doSqlSession(SqlSession sqlSession) {
            return sqlSession.selectMap(statement, parameter, mapKey);
        }/* w w w .  j  ava 2s  . co  m*/
    });
}

From source file:org.mule.module.mybatis.MyBatisConnector.java

License:CPAL v1.0

/**
 * Execute Mybatis select map function/*from  w ww  .  j ava 2  s.c o  m*/
 * 
 * {@sample.xml ../../../doc/mule-mybatis-module.xml.sample mybatis:select-map}
 * 
 * @param statement Fully qualified SQL statement ex: org.mybatis.example.BlogMapper.selectBlog
 * @param payload The parameter to the SQL statement
 * @param mapKey The key to use in the result map
 * @return Result of MyBatis call
 * @throws IOException Io Error
 */
@Processor
public Object selectMap(String statement, @Payload Object payload, String mapKey) throws IOException {
    SqlSession sqlSession = createSqlSession();

    Object result = sqlSession.selectMap(statement, payload, mapKey);
    closeSqlSession(sqlSession);
    return result;
}