zoukankan      html  css  js  c++  java
  • mybatis关联三张表查询对应字段名

    Mapper.xml
    //查询总记录数
    <select id="getPagerList" parameterType="java.util.Map" resultMap="map">
    SELECT
    <choose>
    <!--查询总记录数-->
    <when test="iscount!=null and iscount!=''">
    COUNT(*) id
    </when>
    <otherwise>
    c.*,
    cs.name as cname,
    i.realname as iname,
    s.realname as sname
    </otherwise>
    </choose>
    FROM comment c
    LEFT JOIN course cs ON cs.id = c.cid
    LEFT JOIN instructor i ON i.id = c.iid
    LEFT JOIN student s ON s.id = c.sid
    WHERE 1=1

    <if test="cid != null and cid != ''">
    AND c.cid like concat('%', #{cid}, '%')
    </if>
    <if test="iid != null and iid != ''">
    AND c.iid like concat('%', #{iid}, '%')
    </if>
    <if test="sid != null and sid != ''">
    AND c.sid like concat('%', #{sid}, '%')
    </if>

    <!--条件查询-->
    <select id="getAllWhere" parameterType="java.util.Map" resultMap="map">
    SELECT
    c.*,
    cs.name as cname,
    i.realname as iname,
    s.realname as sname
    FROM comment c
    LEFT JOIN course cs ON cs.id = c.cid
    LEFT JOIN instructor i ON i.id = c.iid
    LEFT JOIN student s ON s.id = c.sid
    WHERE 1=1

    <if test="cid != null and cid != ''">
    AND c.cid like concat('%', #{cid}, '%')
    </if>
    <if test="iid != null and iid != ''">
    AND c.iid like concat('%', #{iid}, '%')
    </if>
    <if test="sid != null and sid != ''">
    AND c.sid like concat('%', #{sid}, '%')
    </if>
    </select>

    <resultMap id="map" type="cn.educate.model.commentModel" autoMapping="true">
    <association property="course" javaType="cn.educate.model.courseModel">
    <result property="name" column="cname" />
    </association>
    <association property="instructor" javaType="cn.educate.model.instructorModel">
    <result property="realname" column="iname"/>
    </association>
    <association property="student" javaType="cn.student.model.studentModel">
    <result property="realname" column="sname"/>
    </association>
    </resultMap>





  • 相关阅读:
    Team Foundation Server操作说明
    SPSS二次开发
    EXT 组件一些属性与方法(Tree)
    win10经验总结
    for语句执行顺序
    数组快速生成range的方法
    切图技巧
    input和textarea区别
    hosts文件位置
    css3动画总结
  • 原文地址:https://www.cnblogs.com/wuqiaoqun/p/13705990.html
Copyright © 2011-2022 走看看