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.*;
21
22
23
24
25 public interface UserDao {
26 @Select({ "select",
27 " u.id, u.username, r.id role_id, r.role_name",
28 " from user u",
29 " left join user_role ur on u.id = ur.user_id",
30 " left join role r on ur.role_id = r.id" })
31 @Results({
32 @Result(id = true, column = "id", property = "id"),
33 @Result(column = "username", property = "username"),
34 @Result(property = "roles", many = @Many(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap1"))
35 })
36 public List<User> findAll();
37
38 @Select({ "select",
39 " u.id, u.username, r.id role_id, r.role_name",
40 " from user u",
41 " left join user_role ur on u.id = ur.user_id",
42 " left join role r on ur.role_id = r.id" })
43 @Results({
44 @Result(id = true, column = "id", property = "id"),
45 @Result(column = "username", property = "username"),
46 @Result(property = "roles", many = @Many(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2"))
47 })
48 public List<User> findAll2();
49
50 @Select({ "select",
51 " u.id, u.username, r.id role_id, r.role_name",
52 " from user u",
53 " left join user_role ur on u.id = ur.user_id",
54 " left join role r on ur.role_id = r.id where u.id in (2, 3)" })
55 @Results({
56 @Result(id = true, column = "id", property = "id"),
57 @Result(column = "username", property = "username"),
58 @Result(property = "role", one = @One(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2"))
59 })
60 public List<User> findAll3();
61
62 @Select("select id teacher_id, username teacher_name from user")
63 @Results(id = "userMap", value = {
64 @Result(id = true, column = "teacher_id", property = "id"),
65 @Result(column = "teacher_name", property = "username")
66 })
67 public List<User> justUseResult();
68
69 @Select({ "select",
70 "u.id, u.username, r.id role_id, r.role_name, ut.id teacher_id, ut.username teacher_name",
71 "from user u",
72 "left join user_role ur on u.id = ur.user_id",
73 "left join role r on ur.role_id = r.id",
74 "left join user ut on ut.id != u.id",
75 "where role_id = 3" })
76 @Results({
77 @Result(id = true, column = "id", property = "id"),
78 @Result(column = "username", property = "username"),
79 @Result(property = "role", one = @One(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao.roleMap2")),
80 @Result(property = "teachers", many = @Many(resultMap = "userMap"))
81 })
82 public User findHeadmaster();
83 }