mybatis like 转义,遍历List

mybatis.xml 中

模糊查询

<if test="studentName != null and studentName !=‘‘ ">
    AND stu.student_name LIKE concat(concat("%",#{studentName}),"%")
</if>

遍历list:

ClassTrainrelMapper.java

List<ClassTrainRel> queryTrainByIds(@Param("trainIds") List<Integer> trainIds);

ClassTrainrelMapper.xml

<select id="queryTrainByIds" resultType="cn.rc.api.entity.ClassTrainRel">
        SELECT
        *
        FROM
        t_class_train_rel
        WHERE
        status = 0
        AND delete_flag = 0
        AND id IN
        <foreach item="item" index="index" collection="trainIds"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>