Mybatis 查询条件in

Mybatis 多条件查询(模糊查询 使用in查询)

xml文件:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE mapper  
  3.   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
  4.   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  5. <mapper namespace="">  
  6.     <select id="selectTeacher" parameterType="map" resultType="map">  
  7.         select t.tid,t.tname,t.taddr  
  8.         from test_teacher t  
  9.         where 1=1  
  10.         <if test="tid != '' and tid != null">  
  11.             and tid=#{tid}  
  12.         </if>  
  13.         <if test="tname != '' and tname != null">  
  14.             and tname like #{tname}  
  15.         </if>  
  16.         <if test="addrs != '' and addrs != null">  
  17.             and taddr in  
  18.             <foreach item="item" index="index" collection="addrs" open="("  
  19.                 separator="," close=")">  
  20.                 #{item}  
  21.             </foreach>  
  22.         </if>  
  23.         ;
  24.     </select>  
  25.   
  26.   
  27. </mapper>  


dao层:

[java]  view plain  copy
  1. package mybatis.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. public interface TestTeacherDao {  
  6.     public List selectTeacher(String tid,String tname,List addrs);  
  7. }  

发现老师查不出来数据。

最后在SQL的最后加上一个分号“;”

猜你喜欢

转载自blog.csdn.net/yueguanyun/article/details/80265273