mybatis做like模糊查詢

mybatis在做Like的模糊查詢的時候,不能直接在sql語句中使用like %關鍵詞,因為這是Mybatis的保留關鍵字。其實想做模糊查詢很簡單,隨便寫下以下幾種供大家參考:

1.  參數中直接加入%%

  param.setUsername("%CD%");       param.setPassword("%11%");

		select id,sex,age,username,password from person where true  			 AND username LIKE #{username}  			AND password LIKE #{password}

2.  bind標籤

          select id,sex,age,username,password             from person            where username LIKE #{pattern}

3. CONCAT

     where username LIKE concat(cancat('%',#{username}),'%')