MyBatis one-to-many mapping XML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.