Skip to content

Commit dda57c1

Browse files
committed
Merge branch 'assoc-with-param-annotation' of https://github.com/lkb2k/mybatis-3 into lkb2k-assoc-with-param-annotation
2 parents be0aed3 + e37d9fb commit dda57c1

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/test/java/org/apache/ibatis/submitted/complex_column/ComplexColumnTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
*/
1616
package org.apache.ibatis.submitted.complex_column;
1717

18-
import java.io.Reader;
19-
import java.sql.Connection;
20-
import java.sql.DriverManager;
21-
22-
import org.junit.Assert;
23-
2418
import org.apache.ibatis.io.Resources;
2519
import org.apache.ibatis.jdbc.ScriptRunner;
2620
import org.apache.ibatis.session.SqlSession;
2721
import org.apache.ibatis.session.SqlSessionFactory;
2822
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
23+
import org.junit.Assert;
2924
import org.junit.BeforeClass;
3025
import org.junit.Test;
3126

27+
import java.io.Reader;
28+
import java.sql.Connection;
29+
import java.sql.DriverManager;
30+
3231
public class ComplexColumnTest {
3332

3433
private static SqlSessionFactory sqlSessionFactory;
@@ -141,4 +140,19 @@ public void testWithComplex4() {
141140
Assert.assertEquals("Smith", parent.getLastName());
142141
sqlSession.close();
143142
}
143+
144+
@Test
145+
public void testWithParamAttributes() {
146+
SqlSession sqlSession = sqlSessionFactory.openSession();
147+
PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
148+
Person person = personMapper.getComplexWithParamAttributes(2l);
149+
Assert.assertNotNull("person must not be null", person);
150+
Assert.assertEquals("Christian", person.getFirstName());
151+
Assert.assertEquals("Poitras", person.getLastName());
152+
Person parent = person.getParent();
153+
Assert.assertNotNull("parent must not be null", parent);
154+
Assert.assertEquals("John", parent.getFirstName());
155+
Assert.assertEquals("Smith", parent.getLastName());
156+
sqlSession.close();
157+
}
144158
}

src/test/java/org/apache/ibatis/submitted/complex_column/Person.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<result property="lastName" column="lastName"/>
2929
<association property="parent" column="parent_id" select="getParentWithoutComplex"/>
3030
</resultMap>
31+
3132
<resultMap id="personMapComplex" type="Person">
3233
<id property="id" column="id"/>
3334
<result property="firstName" column="firstName"/>

src/test/java/org/apache/ibatis/submitted/complex_column/PersonMapper.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package org.apache.ibatis.submitted.complex_column;
1717

18-
import org.apache.ibatis.annotations.ResultMap;
19-
import org.apache.ibatis.annotations.Select;
18+
import org.apache.ibatis.annotations.*;
2019

2120
public interface PersonMapper {
2221

@@ -39,4 +38,24 @@ public interface PersonMapper {
3938
})
4039
@ResultMap("org.apache.ibatis.submitted.complex_column.PersonMapper.personMapComplex")
4140
public 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);
4261
}

0 commit comments

Comments
 (0)