美文网首页
mysql 模糊查询 动态语句 分页

mysql 模糊查询 动态语句 分页

作者: 刘小刀tina | 来源:发表于2020-02-25 20:05 被阅读0次
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tina.mapper.CourseMapper">

    <!--根据id值查询CourseInfoReq的信息-->
    <select id="getCourseInfo" parameterType="String" resultType="com.tina.req.CourseInfoReq">
        SELECT
        tc.id,tc.teacher_id,tc.subject_id,tc.title,tc.price,
        tc.lesson_num,tc.cover,tc.buy_count,tc.view_count,
        tcd.description
        from t_course  as tc left join t_course_description  as tcd
        on tc.id = tcd.id where tc.del_flag = 0 and tcd.del_flag =0 and tc.id =#{id}
    </select>


    <select id="getCourseInfoCondition" resultType="com.tina.req.CourseInfoReq">
           SELECT
                tc.id,tc.teacher_id,tc.subject_id,tc.title,tc.price,
                tc.lesson_num,tc.cover,tc.buy_count,tc.view_count,
                tcd.description
                from t_course  as tc left join t_course_description  as tcd
                on tc.id = tcd.id where tc.del_flag = 0 and tcd.del_flag =0
                order by tc.gmt_modified desc
    </select>

    <select id="getCourseInfoConditionByWaper2" parameterType="com.tina.req.CourseInfoConditionrReq" resultType="com.tina.req.CourseInfoReq" >
        SELECT
        tc.id,
        tc.teacher_id,
        tc.subject_id,
        tc.title,
        tc.price,
        tc.lesson_num,
        tc.cover,
        tc.buy_count,
        tc.view_count,
        tcd.description
        FROM
        t_course AS tc
        LEFT JOIN t_course_description AS tcd ON tc.id = tcd.id
        WHERE
        tc.del_flag = 0
        AND tcd.del_flag = 0

            <if test="id != null and id != ''">
                and tc.id = #{id}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and  tc.teacher_id = #{teacherId}
            </if>
            <if test="subjectId != null and subjectId != ''">
                and  tc.subject_id = #{subjectId}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and  tc.title like CONCAT(CONCAT('%', #{title}), '%')
            </if>
        order by tc.gmt_modified desc
    </select>

    <select id="getCourseInfoConditionByWaper" parameterType="com.tina.req.CourseInfoConditionrReq" resultType="com.tina.req.CourseInfoReq" >
        SELECT
            tc.id,
            tc.teacher_id,
            tc.subject_id,
            tc.title,
            tc.price,
            tc.lesson_num,
            tc.cover,
            tc.buy_count,
            tc.view_count,
            tcd.description
        FROM
            t_course AS tc
            LEFT JOIN t_course_description AS tcd ON tc.id = tcd.id
        WHERE
            tc.del_flag = 0
            AND tcd.del_flag = 0

            <if test="id != null and id != ''">
                AND  tc.id = #{id}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and  tc.teacher_id = #{teacherId}
            </if>
            <if test="subjectId != null and subjectId != ''">
                and  tc.subject_id = #{subjectId}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and  tc.title LIKE  CONCAT(CONCAT('%', #{title}), '%')
            </if>
            order by tc.gmt_modified desc
            limit #{pages} , #{row}
    </select>


</mapper>

相关文章

网友评论

      本文标题:mysql 模糊查询 动态语句 分页

      本文链接:https://www.haomeiwen.com/subject/gvofchtx.html