Java Code Examples for org.apache.ibatis.executor.result.DefaultMapResultHandler#handleResult()

The following examples show how to use org.apache.ibatis.executor.result.DefaultMapResultHandler#handleResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultSqlSession.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {
  //转而去调用selectList
  final List<?> list = selectList(statement, parameter, rowBounds);
  final DefaultMapResultHandler<K, V> mapResultHandler = new DefaultMapResultHandler<K, V>(mapKey,
      configuration.getObjectFactory(), configuration.getObjectWrapperFactory());
  final DefaultResultContext context = new DefaultResultContext();
  for (Object o : list) {
    //循环用DefaultMapResultHandler处理每条记录
    context.nextResultObject(o);
    mapResultHandler.handleResult(context);
  }
  //注意这个DefaultMapResultHandler里面存了所有已处理的记录(内部实现可能就是一个Map),最后再返回一个Map
  return mapResultHandler.getMappedResults();
}
 
Example 2
Source File: DefaultSqlSession.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {
  //转而去调用selectList
  final List<?> list = selectList(statement, parameter, rowBounds);
  final DefaultMapResultHandler<K, V> mapResultHandler = new DefaultMapResultHandler<K, V>(mapKey,
      configuration.getObjectFactory(), configuration.getObjectWrapperFactory());
  final DefaultResultContext context = new DefaultResultContext();
  for (Object o : list) {
    //循环用DefaultMapResultHandler处理每条记录
    context.nextResultObject(o);
    mapResultHandler.handleResult(context);
  }
  //注意这个DefaultMapResultHandler里面存了所有已处理的记录(内部实现可能就是一个Map),最后再返回一个Map
  return mapResultHandler.getMappedResults();
}