Skip to content

Commit b750800

Browse files
committed
Fixes #43. Minor @resultMap refactor.
1 parent 605db6f commit b750800

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/main/java/org/apache/ibatis/annotations/ResultMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2011 The MyBatis Team
2+
* Copyright 2009-2013 The MyBatis Team
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@
2323
@Retention(RetentionPolicy.RUNTIME)
2424
@Target(ElementType.METHOD)
2525
public @interface ResultMap {
26-
String value();
26+
String[] value();
2727
}

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ void parseStatement(Method method) {
286286
String resultMapId = null;
287287
ResultMap resultMapAnnotation = method.getAnnotation(ResultMap.class);
288288
if (resultMapAnnotation != null) {
289-
resultMapId = resultMapAnnotation.value();
289+
String[] resultMaps = resultMapAnnotation.value();
290+
StringBuilder sb = new StringBuilder();
291+
for (String resultMap : resultMaps) {
292+
if (sb.length() > 0) sb.append(",");
293+
sb.append(resultMap);
294+
}
295+
resultMapId = sb.toString();
290296
} else if (isSelect) {
291297
resultMapId = parseResultMap(method);
292298
}

src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,10 @@ public interface SPMapper {
8989
@ResultMap("nameResult,itemResult")
9090
@Options(statementType = StatementType.CALLABLE)
9191
List<List<?>> getNamesAndItemsAnnotatedWithXMLResultMap();
92+
93+
@Select("{call sptest.getnamesanditems()}")
94+
@ResultMap({"nameResult","itemResult"})
95+
@Options(statementType = StatementType.CALLABLE)
96+
List<List<?>> getNamesAndItemsAnnotatedWithXMLResultMapArray();
97+
9298
}

src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,21 @@ public void testGetNamesAndItems_a2() throws SQLException {
773773
}
774774
}
775775

776+
@Test
777+
public void testGetNamesAndItems_a3() throws SQLException {
778+
SqlSession sqlSession = sqlSessionFactory.openSession();
779+
try {
780+
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
781+
782+
List<List<?>> results = spMapper.getNamesAndItemsAnnotatedWithXMLResultMapArray();
783+
assertEquals(2, results.size());
784+
assertEquals(4, results.get(0).size());
785+
assertEquals(3, results.get(1).size());
786+
} finally {
787+
sqlSession.close();
788+
}
789+
}
790+
776791
@Test
777792
public void testGetNamesAndItemsLinked() throws SQLException {
778793
SqlSession sqlSession = sqlSessionFactory.openSession();

0 commit comments

Comments
 (0)