1:columnPrefix
当一个 collection 定义了一个 columnPrefix 属性时,其含义是将前缀自动添加到它关联的那个 resultMap 的 column 中。
关于父子结构的挂靠:
public class A implements Serializable {
private Long id;
private Long parentId;
private String name;
}
public class B extends A{
private List<A> children666;
}
Mapper.xml
collection:一对多关联(has many)
<mapper namespace="com.dao.ADao">
<resultMap id="listWithChildrenMap" type="com.dto.B"
extends="com..mapper.PmsProductCategoryMapper.BaseResultMap">
<collection property="children" resultMap="com.mapper.A.BaseResultMap"
columnPrefix="child_"></collection>
</resultMap>
<select id="listWithChildren666" resultMap="listWithChildrenMap">
select c1.id, c1.name,
c2.id child_id, c2.name child_name
from A c1 left join B c2 on c1.id = c2.parent_id
</select>
</mapper>
sql查询结果集为: xml返回结果集为父子关系:
association: 一对一关联(has one)
<mapper namespace="com.dao.ADao">
<resultMap id="listWithChildrenMap" type="com.dto.B"
extends="com..mapper.PmsProductCategoryMapper.BaseResultMap">
<association property="product" resultMap="com.mapper.A.BaseResultMap"
columnPrefix="p_"></association>
</resultMap>
<select id="listWithChildren666" resultMap="listWithChildrenMap">
select c1.id, c1.name,
c2.id p_id, p.name p_name
from A c1 left join B c2 on c1.id = c2.parent_id
</select>
</mapper>
sql查询结果集: xml返回结果: