0%

Mybatis xml一对多的写法

返回类

1
2
3
4
5
6
7
8
9
List<StudentCourses> queryStudentCourses();

package xxx.StudentCourses

@Data
public class StudentCourses {
private String name;
private List<String> courses;
}
1
2
3
4
5
6
<resultMap id="resultMap" type="xxx.StudentCourses">
<result column="name" property="name" />
<collection property="courses" ofType="string">
<result column="course" />
</collection>
</resultMap>
1
2
3
4
<select id="queryStudentCourses" resultMap="">
SELECT s.name, sc.course FROM student_course sc
JOIN student s ON(s.id = sc.student_id)
</select>