【项目】模糊查询+排序

项目需求:查询上课班信息,把班名排序,汉字英文按照首字母英文字母表排序,数字放在汉字、英文前



思路:直接用SQL查询出数据,然后排序

mapper中的代码:

 <select id="queryTeachclassEntityList" resultType="com.dmsdbj.itoo.teachingManagement.entity.TeachclassEntity">
        <bind name="_strLike" value="'%'+strLike+'%'"/>
        SELECT
            t.teachclass_name AS teachclassName,
            t.teachclass_code AS teachclassCode,
            t.course_id AS courseId,
            t.teacher_id AS teacherId,
            t.capacity,
            t.school_year AS schoolYear,
            t.remain_capacity AS remainCapacity
        FROM
            tt_teachclass t
        <where>
            <choose>
                <when test="strLike!=null and strLike!=''">
                    /*如果有查询条件,则按条件查询*/
                   t.teachclass_code LIKE #{_strLike} OR t.teachclass_name LIKE #{_strLike}
                </when>
                <otherwise>
                    /*如果没有查询条件,则直接查询*/
                   t.teachclass_code != '' AND
                   t.teacher_id=#{teacherId}
                </otherwise>
            </choose>
            AND t.school_year=#{schoolYear}
            AND t.is_delete = '0'
            ORDER BY
            CONVERT (teachclassName USING gbk) COLLATE gbk_chinese_ci ASC
        </where>
    </select>


注:以下代码即把查出的数据进行排序,此处的teachclassName意思是:你想以谁来排序

 ORDER BY
 CONVERT (teachclassName USING gbk) COLLATE gbk_chinese_ci ASC

猜你喜欢

转载自blog.csdn.net/zjy15203167987/article/details/79690164