Mybatis 多条件查询(模糊查询 使用in查询)
xml文件:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="">
- <select id="selectTeacher" parameterType="map" resultType="map">
- select t.tid,t.tname,t.taddr
- from test_teacher t
- where 1=1
- <if test="tid != '' and tid != null">
- and tid=#{tid}
- </if>
- <if test="tname != '' and tname != null">
- and tname like #{tname}
- </if>
- <if test="addrs != '' and addrs != null">
- and taddr in
- <foreach item="item" index="index" collection="addrs" open="("
- separator="," close=")">
- #{item}
- </foreach>
- </if>
- ;
- </select>
- </mapper>
dao层:
- package mybatis.dao;
- import java.util.List;
- public interface TestTeacherDao {
- public List selectTeacher(String tid,String tname,List addrs);
- }
发现老师查不出来数据。
最后在SQL的最后加上一个分号“;”