mybatis 매핑을 사용하여 다른 모음의 개체에 대한 모음을 설정해야합니다.Mybatis 중첩 컬렉션이 열 접두사로 올바르게 작동하지 않습니다.
나를 위해 columnPrefix를 사용하여 승/작동하지만 많은 반복 가능한 열이 있기 때문에 필요합니다. 모두가 잘 작동 columnPrefix으로
<resultMap id="ParentMap" type="org.example.mybatis.Parent">
<id column="Id" jdbcType="VARCHAR" property="id" />
<result column="Name" jdbcType="VARCHAR" property="name" />
<result column="SurName" jdbcType="VARCHAR" property="surName" />
<collection property="childs"
javaType="ArrayList" ofType="org.example.mybatis.Child"
resultMap="ChildMap" columnPrefix="c_"/>
</resultMap>
<resultMap id="ChildMap" type="org.example.mybatis.Parent">
<id column="Id" jdbcType="VARCHAR" property="id" />
<result column="ParentId" jdbcType="VARCHAR" property="parentId" />
<result column="Name" jdbcType="VARCHAR" property="name" />
<result column="SurName" jdbcType="VARCHAR" property="surName" />
<result column="Age" jdbcType="INTEGER" property="age" />
<collection property="toys"
javaType="ArrayList" ofType="org.example.mybatis.Toy"
resultMap="ToyMap" columnPrefix="t_"/>
</resultMap>
<resultMap id="ToyMap" type="org.example.mybatis.Toy">
<id column="Id" jdbcType="VARCHAR" property="id" />
<result column="ChildId" jdbcType="VARCHAR" property="childId" />
<result column="Name" jdbcType="VARCHAR" property="name" />
<result column="Color" jdbcType="VARCHAR" property="color" />
</resultMap>
<sql id="Parent_Column_List">
p.Id, p.Name, p.SurName,
</sql>
<sql id="Child_Column_List">
c.Id as c_Id, c.ParentId as c_ParentId, c.Name as c_Name, c.SurName as c_Surname, c.Age as c_Age,
</sql>
<sql id="Toy_Column_List">
t.Id as t_Id, t.Name as t_Name, t.Color as t_Color
</sql>
<select id="getParent" parameterType="java.lang.String" resultMap="ParentMap" >
select
<include refid="Parent_Column_List"/>
<include refid="Child_Column_List" />
<include refid="Toy_Column_List" />
from Parent p
left outer join Child c on p.Id = c.ParentId
left outer join Toy t on c.Id = t.ChildId
where p.id = #{id,jdbcType=VARCHAR}
하지만, 중첩 된 장난감 컬렉션이 비어 있습니다. 데이터베이스의 Sql 쿼리가 올바르게 작동하고 모든 장난감이 결합됩니다.
내가 놓친 것이 있거나 이것이 mybatis의 버그입니까?
은, 몰라하지만 왜 모든 열은이 아닌 ""입니다.? –
cporte
작은 실수, 관련이 없음 –
좋은 질문 나에게도 같은 문제가있어서 내 방식으로이 해결책을 찾았습니다. 확인해주십시오 –