`
wgbaoweii
  • 浏览: 26931 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

MyBatis表关联

阅读更多

查询主表:
<resultMap type="com.demo.bean.WXGameRankingBean" id="weiboJoinAccountResultMap">
        <id property="id" column="id" />
        <result property="score" column="score" />
        <result property="openid" column="openid" />
        <result property="createTime" column="create_time" />
        <result property="gameid" column="gameid" />
        <result property="subscribe" column="subscribe" />
        <association property="device" column="dp_id" javaType="com.demo.bean.DeviceBean" resultMap="joinAccountResult" />
</resultMap>

所要关联表数据:
<resultMap type="com.demo.bean.DeviceBean" id="joinAccountResult">
    <id property="dpId" column="dp_id" />
    <id property="openId" column="openid" />
</resultMap>

 

<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> 查询语句:
<select id="getDeviceAndRankingByGameid" resultMap="weiboJoinAccountResultMap" parameterType="java.util.HashMap">
     select rr.id as id,rr.score as score,rr.openid as openid,rr.create_time as createTime,
     rr.gameid as gameid,rr.subscribe as subscribe,dd.* from wx_game_ranking rr left outer join zqw_device dd on rr.openid = dd.openid
      where rr.openid = dd.openid and rr.gameid=#{gameid} and rr.subscribe=#{subscribe} group by rr.openid order by rr.score desc,rr.create_time asc
     <if test="limit != null">
         ${limit}
    </if>
</select>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics