zoukankan      html  css  js  c++  java
  • oneselfone

    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>
  • 相关阅读:
    递归要记得返回
    git push的时候报Unable to find remote helper for 'https'的错误
    iphone手机上的click和touch事件
    对jquery的conflict方法的解读
    开发富文本编辑器的一些体会
    使用jquery制作动态加载型菜单
    解决jquery$命名符和其它框架的冲突问题
    基于geolocation来获取经纬度地址
    Python学习笔记2解析数据
    Python学习笔记1数据类型
  • 原文地址:https://www.cnblogs.com/csslcww/p/9912371.html
Copyright © 2011-2022 走看看