<resultMap id="Ecology" type="com.indocloud.indo.common.portal.api.dto.console.about.select.EcologyDTO">
<result column="ecol_id" property="id"/>
<result column="descrition" property="description"/>
<result column="img_url" property="img"/>
<collection property="items"
ofType="com.indocloud.indo.common.portal.api.dto.console.about.select.EcologyItemDTO">
<result column="item_id" property="id"/>
<result column="description" property="description"/>
<result column="sort" property="sort"/>
</collection>
</resultMap>
<select id="getEcology"
resultType="com.indocloud.indo.common.portal.api.dto.console.about.select.EcologyDTO" resultMap="Ecology">
select t1.ecol_id,
ifnull(t1.descrition, ""),
ifnull(t1.img_url, ""),
t2.item_id,
ifnull(t2.description, ""),
t2.sort
from msp_mdl_au_ecology t1
left join msp_mdl_au_ecology_item t2 on t1.ecol_id = t2.ecol_id
where t1.isvalid = '1'
and t2.isvalid = '1'
</select>
注意:
- resultMap 标签可以有多个,只要 id 不重复即可 type 属性 表示你自己对应的实体类
- column 属性 sql查询的列名或着你起的别名
- property 属性 映射的POJO属性名 如果column元素相同,会自动映射到POJO上
- collection 标签 表示一对多关系,一般用于结果集中的集合属性,如List
- ofType 属性 List里面对应的实体类
- javaType:配置java的类型,可以是特定的类完全限定名或Mybatis上下文别名
- jdbcType:配置数据库类型,一般不需要限定,Mybatis已经为我们做了此工作
- typeHander:类型处理器,允许你使用特定的处理器来覆盖默认处理器。需要制定jdbcType和javaType相互转换规则