one2one

Posted csslcww

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了one2one相关的知识,希望对你有一定的参考价值。

多表连接

<mapper namespace="com.abc.dao.IHusbandDao">

    <!-- 多表连接查询 -->

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" javaType="Wife">
            <id column="wid" property="wid" />
            <result column="wname" property="wname" />
        </association>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wid,wname
        from husband,wife
        where wid=wifeId and hid=#{xxx}
    </select>

</mapper>

 

多表单独

<mapper namespace="com.abc.dao.IHusbandDao">

    <!-- 多表单独查询 -->

    <select id="selectWifeByHusband" resultType="Wife">
        select wid,wname from wife where wid=#{jjj}
    </select>

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" 
                     javaType="Wife"
                     select="selectWifeByHusband"
                     column="wifeId"/>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wifeId from husband where hid=#{xxx}
    </select>

</mapper>

多表连接2

    <!-- 多表连接查询 -->

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" javaType="Wife">
            <id column="wid" property="wid" />
            <result column="wname" property="wname" />
        </association>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wid,wname
        from husband,wife
        where wid=hid and hid=#{xxx}
    </select>

 

多表单独2

<mapper namespace="com.abc.dao.IHusbandDao">

    <!-- 多表单独查询 -->

    <select id="selectWifeByHusband" resultType="Wife">
        select wid,wname from wife where wid=#{jjj}
    </select>

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" 
                     javaType="Wife"
                     select="selectWifeByHusband"
                     column="hid"/>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname from husband where hid=#{xxx}
    </select>

</mapper>

 

以上是关于one2one的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Odoo 8 中创建 One2one 关系?

MyBatis之one2one与one2many

Jooq 一次将 one2one 和 one2many 关系数据插入到 2 个表中。如何处理问题和回滚

微信小程序代码片段

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js