Skip to content

Commit d20b56e

Browse files
authored
Merge pull request #2703 from harawata/gh/2693
Referencing collection parameter by name fails ...
2 parents 2d293b5 + cae4537 commit d20b56e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/org/apache/ibatis/reflection/ParamNameResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public Object getNamedParams(Object[] args) {
125125
return null;
126126
} else if (!hasParamAnnotation && paramCount == 1) {
127127
Object value = args[names.firstKey()];
128-
return wrapToMapIfCollection(value, useActualParamName ? names.get(0) : null);
128+
return wrapToMapIfCollection(value, useActualParamName ? names.get(names.firstKey()) : null);
129129
} else {
130130
final Map<String, Object> param = new ParamMap<>();
131131
int i = 0;

src/test/java/org/apache/ibatis/submitted/param_name_resolve/ActualParamNameTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.ibatis.annotations.Select;
2626
import org.apache.ibatis.io.Resources;
2727
import org.apache.ibatis.jdbc.ScriptRunner;
28+
import org.apache.ibatis.session.RowBounds;
2829
import org.apache.ibatis.session.SqlSession;
2930
import org.apache.ibatis.session.SqlSessionFactory;
3031
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
@@ -72,6 +73,11 @@ void testSingleListParameterWhenUseActualParamNameIsTrue() {
7273
long count = mapper.getUserCountUsingListWithAliasIsList(Arrays.asList(1, 2));
7374
assertEquals(2, count);
7475
}
76+
// use actual name #2693
77+
{
78+
long count = mapper.getUserCountUsingList_RowBounds(new RowBounds(0, 5), Arrays.asList(1, 2));
79+
assertEquals(2, count);
80+
}
7581
}
7682
}
7783

@@ -142,6 +148,16 @@ interface Mapper {
142148
"</script>"
143149
})
144150
Long getUserCountUsingArrayWithAliasArray(Integer... ids);
151+
152+
@Select({
153+
"<script>",
154+
" select count(*) from users u where u.id in",
155+
" <foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>",
156+
" #{item}",
157+
" </foreach>",
158+
"</script>"
159+
})
160+
Long getUserCountUsingList_RowBounds(RowBounds rowBounds, List<Integer> ids);
145161
}
146162

147163
}

0 commit comments

Comments
 (0)