Skip to content

Commit

Permalink
Merge pull request #2703 from harawata/gh/2693
Browse files Browse the repository at this point in the history
Referencing collection parameter by name fails ...
  • Loading branch information
harawata authored Sep 24, 2022
2 parents 2d293b5 + cae4537 commit d20b56e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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);
}

}

0 comments on commit d20b56e

Please sign in to comment.