_018_mybatis_自关联_以多对一的方式实现

    <mapper namespace="org.lfz.dao.INewLabelDao">

<!-- <select id="" resultMap="">
select id,name,pid from tb_newslabel where id=#{xxx}
</select> -->

<resultMap type="NewsLabel" id="newsLabelMapper" >
<id column="id" property="id"/>
<result column="name" property="name"/>
<association 
property="parent" 
javaType="NewsLabel" 
select="selectNewsLabelById"
column="pid"/>
</resultMap>

<select id="selectNewsLabelById" resultMap="newsLabelMapper">
select id,name,pid 
from tb_newslabel 
where id=#{xxx}
</select>
</mapper>

猜你喜欢

转载自blog.csdn.net/poiuyppp/article/details/80636874