View Javadoc
1   /*
2    *    Copyright 2009-2023 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    *       https://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.complex_column;
17  
18  import org.apache.ibatis.annotations.One;
19  import org.apache.ibatis.annotations.Param;
20  import org.apache.ibatis.annotations.Result;
21  import org.apache.ibatis.annotations.ResultMap;
22  import org.apache.ibatis.annotations.Results;
23  import org.apache.ibatis.annotations.Select;
24  
25  public interface PersonMapper {
26  
27    Person getWithoutComplex(Long id);
28  
29    Person getWithComplex(Long id);
30  
31    Person getParentWithComplex(Person person);
32  
33    // @formatter:off
34    @Select({
35        "SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName",
36        "FROM Person",
37        "WHERE id = #{id,jdbcType=INTEGER}"
38      })
39    // @formatter:on
40    @ResultMap("personMapComplex")
41    Person getWithComplex2(Long id);
42  
43    // @formatter:off
44    @Select({
45        "SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName",
46        "FROM Person",
47        "WHERE id = #{id,jdbcType=INTEGER}"
48      })
49    // @formatter:on
50    @ResultMap("org.apache.ibatis.submitted.complex_column.PersonMapper.personMapComplex")
51    Person getWithComplex3(Long id);
52  
53    // @formatter:off
54    @Select({
55        "SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName",
56        "FROM Person",
57        "WHERE id = #{id,jdbcType=INTEGER}"
58      })
59    @Results({
60        @Result(id = true, column = "id", property = "id"),
61        @Result(property = "parent", column = "{firstName=parent_firstName,lastName=parent_lastName}", one = @One(select = "getParentWithParamAttributes"))
62      })
63    // @formatter:on
64    Person getComplexWithParamAttributes(Long id);
65  
66    // @formatter:off
67    @Select("SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName"
68        + " FROM Person"
69        + " WHERE firstName = #{firstName,jdbcType=VARCHAR}"
70        + " AND lastName = #{lastName,jdbcType=VARCHAR}"
71        + " LIMIT 1")
72    // @formatter:on
73    Person getParentWithParamAttributes(@Param("firstName") String firstName, @Param("lastName") String lastname);
74  
75  }