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_columnprefix;
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.name 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_columnprefix.RoleDao.roleMap1", columnPrefix = "role_"))
40 })
41
42 List<User> findAll();
43
44
45 @Select({"select",
46 " u.id, u.username, r.id role_id, r.name 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_columnprefix.RoleDao.roleMap2", columnPrefix = "role_"))
54 })
55
56 List<User> findAll2();
57
58
59 @Select({"select",
60 " u.id, u.username, r.id role_id, r.name 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_columnprefix.RoleDao.roleMap2", columnPrefix = "role_"))
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.name role_name,",
84 " f.id friend_id, f.username, fr.id friend_role_id, fr.name friend_role_name",
85 " from user u",
86 " left join user_role ur on u.id = ur.user_id",
87 " left join role r on ur.role_id = r.id",
88 " left join user f on u.friend_id = f.id",
89 " left join user_role fur on f.id = fur.user_id",
90 " left join role fr on fur.role_id = fr.id",
91 " where u.id = #{userId} order by r.id, fr.id"
92 })
93 @Results(id = "userWithFriendMap", value = {
94 @Result(id = true, column = "id", property = "id"),
95 @Result(column = "username", property = "username"),
96 @Result(property = "roles", many = @Many(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_columnprefix.RoleDao.roleMap1", columnPrefix = "role_")),
97 @Result(property = "friend", one = @One(resultMap = "org.apache.ibatis.submitted.annotion_many_one_add_columnprefix.UserDao.userWithFriendMap", columnPrefix = "friend_"))
98 })
99
100 User findUserWithFriend(Integer userId);
101
102 }