File tree Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2013 MyBatis.org.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package domain .blog ;
17
+
18
+ import java .util .List ;
19
+
20
+ public class BlogLite {
21
+
22
+ private int id ;
23
+ private List <PostLite > posts ;
24
+
25
+ public int getId () {
26
+ return id ;
27
+ }
28
+
29
+ public void setId (int id ) {
30
+ this .id = id ;
31
+ }
32
+
33
+ public List <PostLite > getPosts () {
34
+ return posts ;
35
+ }
36
+
37
+ public void setPosts (List <PostLite > posts ) {
38
+ this .posts = posts ;
39
+ }
40
+ }
Original file line number Diff line number Diff line change 35
35
</constructor >
36
36
</resultMap >
37
37
38
+ <resultMap id =" postLiteMap2NestedWithSelect" type =" domain.blog.BlogLite" >
39
+ <id column =" blog_id" property =" id" />
40
+ <collection property =" posts" ofType =" domain.blog.PostLite" >
41
+ <constructor >
42
+ <arg javaType =" domain.blog.PostLiteId" column =" {id=id}" select =" selectPostLiteId" />
43
+ <arg javaType =" _int" column =" blog_id" />
44
+ </constructor >
45
+ </collection >
46
+ </resultMap >
47
+
48
+ <resultMap id =" postLiteMap2NestedWithoutSelect" type =" domain.blog.BlogLite" >
49
+ <id column =" blog_id" property =" id" />
50
+ <collection property =" posts" ofType =" domain.blog.PostLite" >
51
+ <constructor >
52
+ <arg javaType =" domain.blog.PostLiteId" resultMap =" postLiteIdMap" />
53
+ <arg javaType =" _int" column =" blog_id" />
54
+ </constructor >
55
+ </collection >
56
+ </resultMap >
57
+
38
58
<resultMap id =" mutablePostLiteMap" type =" domain.blog.PostLite" >
39
59
<result property =" blogId" column =" blog_id" />
40
60
<association property =" id" column =" id" resultMap =" postLiteIdMap" />
48
68
select id, blog_id from post where blog_id is not null
49
69
</select >
50
70
71
+ <select id =" selectPostLite2NestedWithSelect" resultMap =" postLiteMap2NestedWithSelect" >
72
+ select id, 1 as blog_id from post where blog_id is not null
73
+ </select >
74
+
75
+ <select id =" selectPostLite2NestedWithoutSelect" resultMap =" postLiteMap2NestedWithoutSelect" >
76
+ select id, 1 as blog_id from post where blog_id is not null
77
+ </select >
78
+
79
+ <select id =" selectPostLiteId" resultMap =" postLiteIdMap" >
80
+ select ${id} as id from (values(0)) as t
81
+ </select >
82
+
51
83
<select id =" selectMutablePostLite" resultMap =" mutablePostLiteMap" >
52
84
select id, blog_id from post where blog_id is not null
53
85
</select >
Original file line number Diff line number Diff line change @@ -479,6 +479,20 @@ public void shouldFindAllPostLites() throws Exception {
479
479
assertEquals (4 , posts .size ());
480
480
}
481
481
482
+ @ Test
483
+ public void shouldFindAllPostLitesWithNestedSelect () throws Exception {
484
+ final BlogLite blog = manager .selectOne ("domain.blog.mappers.PostMapper.selectPostLite2NestedWithSelect" );
485
+ assertNotNull (blog );
486
+ assertEquals (4 , blog .getPosts ().size ());
487
+ }
488
+
489
+ @ Test
490
+ public void shouldFindAllPostLitesWithNestedResultMap () throws Exception {
491
+ final BlogLite blog = manager .selectOne ("domain.blog.mappers.PostMapper.selectPostLite2NestedWithoutSelect" );
492
+ assertNotNull (blog );
493
+ assertEquals (4 , blog .getPosts ().size ());
494
+ }
495
+
482
496
@ Test
483
497
public void shouldFindAllMutablePostLites () throws Exception {
484
498
List <PostLite > posts = manager .selectList ("domain.blog.mappers.PostMapper.selectMutablePostLite" );
You can’t perform that action at this time.
0 commit comments