MyBatic:查询语句

1、模糊查询:

  1. sql中字符串拼接

     SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');

  2. 使用 ${...} 代替 #{...}

     SELECT * FROM tableName WHERE name LIKE '%${text}%';

 

2、数组查询:

  

select * from rb_borrow_tag rbt where 1=1
        <if test="tagIds != null" >
    and    rbt.id in 
        <foreach item="item" index="index" collection="tagIds" open="(" separator="," close=")">  
                  #{item}  
        </foreach>  
    </if>
        ORDER BY  id desc
    </select>

 

posted @ 2016-03-31 09:56  自朗活  阅读(269)  评论(0编辑  收藏  举报