• mybatis多表查询


    1、例子:

    实体类:

    <select id="findAllMsgByTagId" parameterType="com.yunkuan.entity.ParkClass" resultMap="parkMap" >
    select * from parkclass pc join parkclasstag pct on(pc.classtaglevel=pct.id)
    join parent p on(pc.parentid=p.id)
    where pc.parkid=#{parkid} and pct.id=#{classtaglevel}
    </select>

    <!-- 指定关联属性加载 -->

    <resultMap id="parkMap" type="com.yunkuan.entity.ParkClassParent">
    <id property="id" column="id"/>
    <result property="parkid" column="parkid"/>
    <result property="childname" column="childname"/>
    <result property="classtaglevel" column="classtaglevel"/>
    <result property="parentid" column="parentid"/>
    <result property="timer" column="timer"/>

    ParkClassTag类:
    <association property="parkClassTag" javaType="com.yunkuan.entity.ParkClassTag">
    <id property="id" column="id"/>
    <result property="id" column="id"/>
    <result property="tagname" column="tagname"/>
    <result property="timer" column="timer"/>
    </association>

    Parent类:
    <association property="parent" javaType="com.yunkuan.entity.Parent">
    <id property="id" column="id"/>
    <result property="parentname" column="parentname"/>
    <result property="parentpass" column="parentpass"/>
    <result property="phone" column="phone"/>
    <result property="address" column="address"/>
    <result property="balance" column="balance"/>
    <result property="timer" column="timer"/>
    </association>
    </resultMap>

    如果多表查询里有相同的字段:

    例子:

  • 相关阅读:
    Spark Executor内存管理
    Spring中Bean的生命周期及其扩展点
    NIO非阻塞IO
    TCP,UDP和socket,Http之间联系和区别
    md5加密,md5加盐加密和解密
    线程监测方法多久没被调用
    项目部署后,替换.class文件不生效
    mysql存储过程导入表
    java生成二维码
    Map中keySet和entrySet的区别
  • 原文地址:https://www.cnblogs.com/chong518/p/5289024.html
Copyright © 2020-2023  润新知