View Javadoc
1   /*
2    *    Copyright 2009-2021 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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   * @author lvyang
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  }