1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.annotion_many_one_add_resultmapid;
17
18 import java.util.List;
19
20 import org.apache.ibatis.annotations.Many;
21 import org.apache.ibatis.annotations.One;
22 import org.apache.ibatis.annotations.Result;
23 import org.apache.ibatis.annotations.Results;
24 import org.apache.ibatis.annotations.Select;
25
26
27
28
29 public interface UserDao {
30
31 @Select({"select",
32 " u.id, u.username, r.id role_id, r.role_name",
33 " from user u",
34 " left join user_role ur on u.id = ur.user_id",
35 " left join role r on ur.role_id = r.id"})
36 @Results({
37 @Result(id = true, column = "id", property = "id"),
38 @Result(column = "username", property = "username"),
39 @Result(property = "roles", many = @Many(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap1"))
40 })
41
42 List<User> findAll();
43
44
45 @Select({"select",
46 " u.id, u.username, r.id role_id, r.role_name",
47 " from user u",
48 " left join user_role ur on u.id = ur.user_id",
49 " left join role r on ur.role_id = r.id"})
50 @Results({
51 @Result(id = true, column = "id", property = "id"),
52 @Result(column = "username", property = "username"),
53 @Result(property = "roles", many = @Many(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2"))
54 })
55
56 List<User> findAll2();
57
58
59 @Select({"select",
60 " u.id, u.username, r.id role_id, r.role_name",
61 " from user u",
62 " left join user_role ur on u.id = ur.user_id",
63 " left join role r on ur.role_id = r.id where u.id in (2, 3)"})
64 @Results({
65 @Result(id = true, column = "id", property = "id"),
66 @Result(column = "username", property = "username"),
67 @Result(property = "role", one = @One(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2"))
68 })
69
70 List<User> findAll3();
71
72
73 @Select("select id teacher_id, username teacher_name from user")
74 @Results(id = "userMap", value = {
75 @Result(id = true, column = "teacher_id", property = "id"),
76 @Result(column = "teacher_name", property = "username")
77 })
78
79 List<User> justUseResult();
80
81
82 @Select({"select",
83 "u.id, u.username, r.id role_id, r.role_name, ut.id teacher_id, ut.username teacher_name",
84 "from user u",
85 "left join user_role ur on u.id = ur.user_id",
86 "left join role r on ur.role_id = r.id",
87 "left join user ut on ut.id != u.id",
88 "where role_id = 3"})
89 @Results({
90 @Result(id = true, column = "id", property = "id"),
91 @Result(column = "username", property = "username"),
92 @Result(property = "role", one = @One(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2")),
93 @Result(property = "teachers", many = @Many(resultMap = "userMap"))
94 })
95
96 User findHeadmaster();
97 }