[Item] Fuzzy query + sorting

Project requirements: Query class information, sort class names, Chinese characters and English are sorted according to the first letter of the English alphabet, and numbers are placed before Chinese characters and English.



Idea: query data directly with SQL, and then sort

Code in 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!=''">
                    /* If there are query conditions, query by conditions */
                   t.teachclass_code LIKE #{_strLike} OR t.teachclass_name LIKE #{_strLike}
                </when>
                <otherwise>
                    /* If there is no query condition, query directly */
                   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>


Note: The following code sorts the detected data, where teachclassName means: who do you want to sort by

ORDER BY
 CONVERT (teachclassName USING gbk) COLLATE gbk_chinese_ci ASC

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325725156&siteId=291194637