ReZero's Utopia.

Mybatis collection mapping

Word count: 210Reading time: 1 min
2019/09/06 Share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hand.persistence.AttachmentTypeLjMapper">


<resultMap type="com.hand.dto.AttachmentTypeDTO" id="atd">
<id property="id" column="id" />
<result property="tenantId" column="tenant_id" />
<result property="versionNumber" column="version_number" />
<collection property="formatList" ofType="com.hand.hcf.app.mdata.train.lj.domain.AttachmentFormatLj">
<id property="id" column="format_id" />
<result property="formatTypeCode" column="format_type_code" />
<result property="versionNumber" column="format_version_number" />
</collection>
</resultMap>

<select id="selectByCondition" resultMap="atd">
select
t.id id,
t.tenant_id tenant_id,
t.version_number version_number,
f.id format_id,
f.format_type_code format_type_code,
f.version_number format_version_number
from sys_attachment_type_lj t
left join sys_attachment_format_ass_lj tf on t.id = tf.attachment_type_id
left join sys_attachment_format_lj f on f.id = tf.attachment_format_id
<where>
<if test="attachmentCode != null and attachmentCode != ''">
<bind name="attachmentCodeLike" value="'%' + attachmentCode + '%'" />
and t.attachment_code like #{attachmentCodeLike}
</if>
<if test="enabled != null">
and t.enabled = #{enabled}
</if>
</where>
</select>

</mapper>
CATALOG