列如:
table user{员工表
    uid;
    uname;
    uage;
    usalary;
 }
table lend{借款表
    lid;
    luserid;借款人id
    lmoney;
    ldate;
    lwarrant_userid;担保人id
}查询一个借款单
(借款单的详细信息、借款人的姓名、借款担保人的姓名)
在mybatis中怎么写映射文件
    

解决方案 »

  1.   


    <typeAlias alias="User" type="xxx.User" />
    <typeAlias alias="Lend" type="xxx.Lend" /> <resultMap id="get-user-result" class="User">
    <result property="uid" column="UID" />
    <result property="uname" column="UNAME" />
    <result property="uage" column="UAGE" />
    <result property="usalary" column="USALARY" />
    </resultMap>

    <resultMap id="get-lend-result" class="Lend">
    <result property="lid" column="LID" />
    <result property="luserid" column="LUSERID" select="getUserById"/>
    <result property="lmoney" column="LMONEY" />
    <result property="lwarrant_userid" column="LWARRANT_USERID" select="getUserById"/>
    </resultMap> <select id="selectLendById" parameterClass="int"
    resultMap="get-lend-result">
    select * from LEND where ID = #id#
    </select>

    <select id="getUserById" parameterClass="int"
    resultMap="get-user-result">
    select * from USER where ID = #id#
    </select>
      

  2.   

    等了好久才有人给个答案,先谢谢啊
    我问题已经解决,其实和你写的差不多   
     <resultMap id="get-lend-result" class="Lend">
            <result property="lid" column="LID" />
            <result property="luserid" column="LUSERID" />
            <result property="lmoney" column="LMONEY" />
            <result property="lwarrant_userid" column="LWARRANT_USERID"/>
            <association property="lendPerson"  column="LUSERID" select="selectUserByOid"></association>
    <association property="warrantPerson"  column="LWARRANT_USERID" select="selectUserByOid"></association>
        </resultMap>在实体类中加两个属性:
    private User lendPerson;
    private User warrantPerson;
      

  3.   


    selectLendById这个就能查出吗?
    实体类做什么修改?