Skip to content

Commit 058d6d1

Browse files
committed
Add columnPrefix to @Arg as well.
1 parent 25a41f8 commit 058d6d1

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
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.
@@ -46,4 +46,9 @@
4646
String resultMap() default "";
4747

4848
String name() default "";
49+
50+
/**
51+
* @since 3.5.0
52+
*/
53+
String columnPrefix() default "";
4954
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMa
609609
nullOrEmpty(arg.select()),
610610
nullOrEmpty(arg.resultMap()),
611611
null,
612-
null,
612+
nullOrEmpty(arg.columnPrefix()),
613613
typeHandler,
614614
flags,
615615
null,

src/test/java/org/apache/ibatis/submitted/constructor_columnprefix/ConstructorColumnPrefixTest.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,31 @@ public void shouldGetArticles() {
5050
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
5151
Mapper mapper = sqlSession.getMapper(Mapper.class);
5252
List<Article> articles = mapper.getArticles();
53-
assertEquals(2, articles.size());
54-
Article article1 = articles.get(0);
55-
assertEquals(Integer.valueOf(1), article1.getId().getId());
56-
assertEquals("Article 1", article1.getName());
57-
assertEquals("Mary", article1.getAuthor().getName());
58-
assertEquals("Bob", article1.getCoauthor().getName());
59-
Article article2 = articles.get(1);
60-
assertEquals(Integer.valueOf(2), article2.getId().getId());
61-
assertEquals("Article 2", article2.getName());
62-
assertEquals("Jane", article2.getAuthor().getName());
63-
assertEquals("Mary", article2.getCoauthor().getName());
53+
assertArticles(articles);
6454
}
6555
}
6656

57+
@Test
58+
public void shouldGetArticlesAnno() {
59+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
60+
Mapper mapper = sqlSession.getMapper(Mapper.class);
61+
List<Article> articles = mapper.getArticlesAnno();
62+
assertArticles(articles);
63+
}
64+
}
65+
66+
protected void assertArticles(List<Article> articles) {
67+
assertEquals(2, articles.size());
68+
Article article1 = articles.get(0);
69+
assertEquals(Integer.valueOf(1), article1.getId().getId());
70+
assertEquals("Article 1", article1.getName());
71+
assertEquals("Mary", article1.getAuthor().getName());
72+
assertEquals("Bob", article1.getCoauthor().getName());
73+
Article article2 = articles.get(1);
74+
assertEquals(Integer.valueOf(2), article2.getId().getId());
75+
assertEquals("Article 2", article2.getName());
76+
assertEquals("Jane", article2.getAuthor().getName());
77+
assertEquals("Mary", article2.getCoauthor().getName());
78+
}
79+
6780
}

src/test/java/org/apache/ibatis/submitted/constructor_columnprefix/Mapper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,28 @@
1717

1818
import java.util.List;
1919

20+
import org.apache.ibatis.annotations.Arg;
21+
import org.apache.ibatis.annotations.ConstructorArgs;
22+
import org.apache.ibatis.annotations.Select;
23+
2024
public interface Mapper {
2125

2226
List<Article> getArticles();
2327

28+
@ConstructorArgs({
29+
@Arg(id = true, resultMap = "keyRM", columnPrefix = "key_", javaType = EntityKey.class),
30+
@Arg(column = "name", javaType = String.class),
31+
@Arg(resultMap = "authorRM", columnPrefix = "author_", javaType = Author.class),
32+
@Arg(resultMap = "authorRM", columnPrefix = "coauthor_", javaType = Author.class),
33+
})
34+
@Select({
35+
"select id key_id, name, author.id author_id, author.name author_name,",
36+
" coauthor.id coauthor_id, coauthor.name coauthor_name",
37+
"from articles",
38+
"left join authors author on author.id = articles.author_id",
39+
"left join authors coauthor on coauthor.id = articles.coauthor_id",
40+
"order by articles.id"
41+
})
42+
List<Article> getArticlesAnno();
43+
2444
}

0 commit comments

Comments
 (0)