org.apache.ibatis.executor.result.DefaultMapResultHandler Java Examples

The following examples show how to use org.apache.ibatis.executor.result.DefaultMapResultHandler. 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: BlogMain.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void selectHandler(SqlSession session, Configuration configuration) {
	BlogMapper mapper = session.getMapper(BlogMapper.class);
	// DefaultResultHandler内置结果处理器
	DefaultResultHandler defaultHandler = new DefaultResultHandler();
	// System.out.println(mapper.selectBlogsByHandler("zhaohui",
	// defaultHandler));
	System.out.println(defaultHandler.getResultList());

	// DefaultMapResultHandler内置结果处理器
	DefaultMapResultHandler<Long, Blog> defaultMapResultHandler = new DefaultMapResultHandler<Long, Blog>("id",
			configuration.getObjectFactory(), configuration.getObjectWrapperFactory(),
			configuration.getReflectorFactory());
	mapper.selectBlogsByHandler("zhaohui", defaultMapResultHandler);
	System.out.println(defaultMapResultHandler.getMappedResults());
}
 
Example #2
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 #3
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();
}