• mybatis 一对多映射 xml


    最近在做一个评论功能时,涉及到一个评论对应多张图片,这个时候想一个方法全部返回,就需要在xml中进行配置。由于好久没用到一对多的配置,所以很长时间才写出来,mark一下

    返回对象:

    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;

    对应xml配置文件:

    <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"/>      

            <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>

  • 相关阅读:
    TimeVal类——Live555源码阅读(一)基本组件类
    QT国际化 一 (lupdate/linguits/lrelease)
    qmake的使用
    将Apache加入到linux系统service
    ubuntu下编译VLC
    Ubuntu14.04安装intel集显驱动
    net-snmp的dateandtime数据类型
    MySQL的主从复制原理
    【iOS开发-25】UIDevice查看系统信息,从一个问题開始怎样高速找到自己想要的属性和方法并看懂它
    POJ 3279 Fliptile (二进制+搜索)
  • 原文地址:https://www.cnblogs.com/govoid/p/5557651.html
Copyright © 2020-2023  润新知