select s.id, s.NAME AS NAME, s.age, s.sex, l.NAME AS schoolname, s.school_id as schoolId FROM student s left JOIN school l ON s.school_id = l.id <where> <if test="id !=null"> and s.id =#{id} </if> <if test="name != null and name != ''"> and s.name like concat("%", #{name},"%") </if> </where> </select>
concat("%", #{name},"%") 拼接语句