首先我们在mapper接口写一个查询方法,@Param是注解,为参数声明的意思。
List<Teacher> FindBy_Like(@Param("tname") String name,@Param("tsex") String color,@Param("tage") int price);
接下来我们在xml里面写
<select id="FindBy_Like" resultType="Teacher">
select * from teacher
<where>
<if test="tname !=null and tname!=''"></if>
tname like concat('%',#{tname},'%')
<if test="tsex !=null and tsex!=''"></if>
and tsex like concat('%',#{tsex},'%')
<if test="tage!=null and tage!=''"></if>
and tage < #{tage}
</where>
</select>
就可以实现动态sql语句了,