Recently in a comment function, involves a comment corresponding to a number of pictures, this time to think of a method to return all, you need to configure in the XML. It took a long time to write, Mark, because it was useless to a pair of more configurations.
Return object:
private String commentid;
Private String commentcontent;
Private Date commenttime;
private String productId;
private String userId;
private String userName;
private String headimg;
private Integer startnum;
private Integer supportnum;
private list<commentimg> commentimgs;
Corresponding XML configuration file:
<mapper namespace= "Com.lefang.lf.vo.CommentGrid">
<resultmap type= "Com.lefang.lf.vo.CommentGrid" id= "commentgrid" >
<ID Column= "comment_id" Property = "Commentid" />
<result column= "Comment_content" Property = "Commentcontent" />
<result column= "Comment_time" Property = "Commenttime" />
<result column= "Head_img" Property = "headimg" />
<result column= "product_id" Property = "productId" />
<result column= "user_id" Property = "userId"/> /c25>
<result column= "User_name" Property = "UserName"/>
<result column= "Start_num" Property = "Startnum"/>
<result column= "Support_num" Property = "Supportnum"/>
<collection property = "Commentimgs" ofType= " COM.LEFANG.LF.MODEL.COMMENTIMG ">
<ID column="img_id" property="id" />
<result column= "Img_url" Property = "Imgurl" />
</collection>
</resultmap>
<select id= "grid" resultmap= "Commentgrid">
SELECT DISTINCT
c.id comment_id,
c.comment_content,
c.comment_time,
c.product_id,
C.start_num,
C.support_num,
c.user_id,
ci.id img_id,
CI. Img_url
from
l_lf_comment C left JOIN l_lf_comment_img CI on ci.comment_id = c.id
where 1 = 1
<if test= "Productid!=null">
and c.product_id =#{productid}
</if>
ORDER by Comment_time desc
</select>
</mapper>
MyBatis one-to-many mapping XML