首页 > 其他 > 详细

mybatis 一对多查询

时间:2016-03-04 17:46:07      阅读:181      评论:0      收藏:0      [点我收藏+]
<resultMap type="com.cloudsoaring.web.course.entity.PlanNodeEntity" id="selectPlanNodeMap">
        <result property="id" column="ID"/>
        <result property="planId" column="PLAN_ID"/>
        <result property="parentId" column="PARENT_ID"/>
        <result property="level" column="LEVEL"/>
        <result property="nodeOrder" column="NODE_ORDER"/>
        <result property="content" column="CONTENT"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="updateDate" column="UPDATE_DATE"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="nodeName" column="NODE_NAME"/>
        
        <collection property="childPlanNodes" column="{parentId=id}" select="selectChildPlanNode" /> 
    </resultMap> 
    <!-- 根据计划id检索父节点信息 -->
    <select id="selectPlanNodeList" resultMap="selectPlanNodeMap">
        SELECT
            ID ,
            PLAN_ID,
            PARENT_ID,
            LEVEL,
            NODE_ORDER,
            CONTENT,
            CREATE_DATE,
            CREATE_USER,
            UPDATE_DATE,
            UPDATE_USER,
            NODE_NAME
        FROM
            tb_plan_node
         where PLAN_ID=#{planId} and LEVEL=1
         ORDER BY NODE_ORDER  
    </select>
    <!-- 根据父节点id检索子节点信息 -->
    <resultMap type="com.cloudsoaring.web.course.entity.PlanNodeEntity" id="selectChildPlanNodeMap">
        <result property="id" column="ID"/>
        <result property="planId" column="PLAN_ID"/>
        <result property="parentId" column="PARENT_ID"/>
        <result property="level" column="LEVEL"/>
        <result property="nodeOrder" column="NODE_ORDER"/>
        <result property="content" column="CONTENT"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="updateDate" column="UPDATE_DATE"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="nodeName" column="NODE_NAME"/>
        <collection property="nodeCourses" column="{planNodeId=id}" select="searchPlanCourse" />
    </resultMap>  
    <select id="selectChildPlanNode" resultMap="selectChildPlanNodeMap">
        SELECT
            ID ,
            PLAN_ID,
            PARENT_ID,
            LEVEL,
            NODE_ORDER,
            CONTENT,
            CREATE_DATE,
            CREATE_USER,
            UPDATE_DATE,
            UPDATE_USER,
            NODE_NAME
        FROM
            tb_plan_node
         where PARENT_ID=#{parentId} and LEVEL=2
    </select>
    
    

 

mybatis 一对多查询

原文:http://www.cnblogs.com/Fang-Z/p/5242868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!