1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34 @Select({
35 "SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName",
36 "FROM Person",
37 "WHERE id = #{id,jdbcType=INTEGER}"
38 })
39
40 @ResultMap("personMapComplex")
41 Person getWithComplex2(Long id);
42
43
44 @Select({
45 "SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName",
46 "FROM Person",
47 "WHERE id = #{id,jdbcType=INTEGER}"
48 })
49
50 @ResultMap("org.apache.ibatis.submitted.complex_column.PersonMapper.personMapComplex")
51 Person getWithComplex3(Long id);
52
53
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
64 Person getComplexWithParamAttributes(Long id);
65
66
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
73 Person getParentWithParamAttributes(@Param("firstName") String firstName, @Param("lastName") String lastname);
74
75 }