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