Skip to content

Referencing collection parameter by name fails ... #2703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Object getNamedParams(Object[] args) {
return null;
} else if (!hasParamAnnotation && paramCount == 1) {
Object value = args[names.firstKey()];
return wrapToMapIfCollection(value, useActualParamName ? names.get(0) : null);
return wrapToMapIfCollection(value, useActualParamName ? names.get(names.firstKey()) : null);
} else {
final Map<String, Object> param = new ParamMap<>();
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
Expand Down Expand Up @@ -72,6 +73,11 @@ void testSingleListParameterWhenUseActualParamNameIsTrue() {
long count = mapper.getUserCountUsingListWithAliasIsList(Arrays.asList(1, 2));
assertEquals(2, count);
}
// use actual name #2693
{
long count = mapper.getUserCountUsingList_RowBounds(new RowBounds(0, 5), Arrays.asList(1, 2));
assertEquals(2, count);
}
}
}

Expand Down Expand Up @@ -142,6 +148,16 @@ interface Mapper {
"</script>"
})
Long getUserCountUsingArrayWithAliasArray(Integer... ids);

@Select({
"<script>",
" select count(*) from users u where u.id in",
" <foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>",
" #{item}",
" </foreach>",
"</script>"
})
Long getUserCountUsingList_RowBounds(RowBounds rowBounds, List<Integer> ids);
}

}