Mybatis返回一个Map中包含多个List问题

数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Data
public class First {
private String id;
private String firstName;
private List<Second> secondList;
}
@Data
public class Second {
private String secondId;
private String secondName;
private List<Third> thirdList;
}
@Data
public class Third {
private String thirdId;
private String thirdName;
}

目的

返回一个List<First>

DAO层

1
List<First> selectAllLevel();

Mapper层

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<mapper namespace="com.ymt.zyj.threelevellinkage.dao.LevelLinkageMapper">
<select id="selectAllLevel" resultMap="OrderMap">
SELECT f.id,f.firstname,s.secondid,s.secondname,t.thirdid,t.thirdname
from t_first f,
t_second s,
t_third t
WHERE f.id = s.firstId
AND s.id = t.secondId
</select>
<!--将数据库的字段和entity字段一一匹配-->
<resultMap type="com.ymt.zyj.threelevellinkage.entity.First" id="OrderMap">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="firstName" jdbcType="VARCHAR" property="firstName"/>
<collection property="secondList" ofType="com.ymt.zyj.threelevellinkage.entity.Second"
javaType="java.util.List">
<result column="secondId" jdbcType="INTEGER" property="secondId"/>
<result column="secondName" jdbcType="INTEGER" property="secondName"/>
<collection property="thirdList" ofType="com.ymt.zyj.threelevellinkage.entity.Third"
javaType="java.util.List">
<result column="thirdId" jdbcType="INTEGER" property="thirdId"/>
<result column="thirdName" jdbcType="INTEGER" property="thirdName"/>
</collection>
</collection>
</resultMap>
</mapper>

返回信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
[
{
"id": "1",
"firstName": "户外玩具",
"secondList": [
{
"secondId": "1",
"secondName": "自行车",
"thirdList": [
{
"thirdId": "1",
"thirdName": "自行车轮胎"
},
{
"thirdId": "2",
"thirdName": "自行车把手"
}
]
},
{
"secondId": "2",
"secondName": "摩托车",
"thirdList": [
{
"thirdId": "3",
"thirdName": "摩托车轮胎"
},
{
"thirdId": "4",
"thirdName": "摩托车把手"
}
]
}
]
},
{
"id": "2",
"firstName": "室内玩具",
"secondList": [
{
"secondId": "3",
"secondName": "洋娃娃",
"thirdList": [
{
"thirdId": "5",
"thirdName": "洋娃娃衣服"
},
{
"thirdId": "6",
"thirdName": "洋娃娃裤子"
}
]
},
{
"secondId": "4",
"secondName": "毛绒熊",
"thirdList": [
{
"thirdId": "7",
"thirdName": "毛绒熊衣服"
},
{
"thirdId": "8",
"thirdName": "毛绒熊裤子"
}
]
}
]
},
{
"id": "3",
"firstName": "教材教具",
"secondList": [
{
"secondId": "5",
"secondName": "语文书",
"thirdList": [
{
"thirdId": "9",
"thirdName": "作文教材"
},
{
"thirdId": "10",
"thirdName": "文言文教材"
}
]
},
{
"secondId": "6",
"secondName": "英语书",
"thirdList": [
{
"thirdId": "11",
"thirdName": "英语听力"
},
{
"thirdId": "12",
"thirdName": "英语阅读"
}
]
}
]
}
]
赏个🍗吧
0%