码迷,mamicode.com
首页 > 其他好文 > 详细

oneselfone

时间:2018-11-06 00:49:49      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:多表   nes   连接查询   dao   select   sla   表单   表连接   one   

1.one2many-多表连接查询


<mapper namespace="com.abc.dao.INewsLabelDao"> <!-- 多表连接查询 --> <resultMap type="NewsLabel" id="newslabelMap"> <id column="ptid" property="id"/> <result column="ptname" property="name"/> <collection property="children" ofType="NewsLabel"> <id column="cdid" property="id"/> <result column="cdname" property="name"/> </collection> </resultMap> <select id="selectNewsLabelById" resultMap="newslabelMap"> select pt.id ptid,pt.name ptname,cd.id cdid,cd.name cdname from newslabel pt,newslabel cd where pt.id=cd.pid and pt.id=#{xxx} </select> </mapper>

2.one2many-多表单独查询

 

<mapper namespace="com.abc.dao.INewsLabelDao">
    
    <!-- 多表单独查询 -->

    <select id="selectChildrenByParent" resultMap="newslabelMap">
        select id,name from newslabel where pid=#{jjj}
    </select>

    <resultMap type="NewsLabel" id="newslabelMap">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <collection property="children" 
                    ofType="NewsLabel"
                    select="selectChildrenByParent"
                    column="id"/>
    </resultMap>

    <select id="selectNewsLabelById" resultMap="newslabelMap">
        select id,name from newslabel where id=#{xxx}
    </select>

</mapper>

3.one2many-多表单独查询2

<mapper namespace="com.abc.dao.INewsLabelDao">
    
    <!-- 多表单独查询 -->

    <select id="selectChildrenByParent" resultMap="newslabelMap">
        select id,name from newslabel where pid=#{jjj}
    </select>

    <resultMap type="NewsLabel" id="newslabelMap">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <collection property="children" 
                    ofType="NewsLabel"
                    select="selectChildrenByParent"
                    column="id"/>
    </resultMap>

</mapper>

4.many2one-多表单独查询

<mapper namespace="com.abc.dao.INewsLabelDao">
    
    <!-- 多表单独查询 -->

    <resultMap type="NewsLabel" id="newslabelMap">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <association property="parent" 
                     javaType="NewsLabel"
                     select="selectNewsLabelById"
                     column="pid"/>
    </resultMap>
    
    <select id="selectNewsLabelById" resultMap="newslabelMap">
        select id,name,pid from newslabel where id=#{jjj}
    </select>

</mapper>

 

oneselfone

标签:多表   nes   连接查询   dao   select   sla   表单   表连接   one   

原文地址:https://www.cnblogs.com/csslcww/p/9912371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!