List<Map<String, Object>> list = sqlSession.selectList("com.xxx.xxxMapper.execSql", selectParameter); private Cursor<Map<String, Object>> cursor = new ListCursorAdapter<>(list); private Iterator<Map<String, Object>> cursorIterator = cursor.iterator();
import org.apache.ibatis.cursor.Cursor; import org.apache.ibatis.exceptions.PersistenceException; import org.jetbrains.annotations.NotNull; import java.util.Iterator; import java.util.List; public class ListCursorAdapter<T> implements Cursor<T> { private final Iterator<T> iterator; private boolean isOpen = true; public ListCursorAdapter(List<T> list) { this.iterator = list.iterator(); } @Override public boolean isOpen() { return isOpen; } @Override public boolean isConsumed() { return false; } @Override public int getCurrentIndex() { return 0; } public T getCurrentValue() { if (!iterator.hasNext()) { throw new PersistenceException("Cursor is not on a valid row"); } return iterator.next(); } public boolean next() { return iterator.hasNext() && iterator.next() != null; } @Override public void close() { isOpen = false; } @NotNull @Override public Iterator<T> iterator() { return iterator; } }