客户要求查询条件中带%,即可以查询内容中带百分号的内容,项目用的是ibatis 框架,如何能实现?

解决方案 »

  1.   

    模糊查询阿,你要给它钱它才给你办事如下: name like '%$name$%' 将#号改为$符号
      

  2.   

    和ibatis有什么关系?你能不能在你当前的数据库写出来一个查询%的语句?能就把它写到ibatis里面去。
      

  3.   

    比如Oracle用escape函数表示转义with t as (select 'abc' a from dual 
                 union all
               select 'a%c' a from dual)
               
    select * from t where a like 'a~%c' escape'~';想查询%,就在%前面加~,代表这是个百分号字符,而不是通配符。
      

  4.   

    直接写sql,我也会写,就像楼上写的那样,用转义字符
    select * from t where a like 'a~%c' escape'~';
    但是在ibatis 中如何实现? 对于参数中带百分号的条件,难道动态先拼串,如下:
    name = 'a~%c' escape'~'
    select * from t where a like %$name$%
      

  5.   


    name = "%~%%"
    select * from t where a like #name#  escape'~'有什么问题吗你写
      

  6.   

    <select id="selectBlogsLike" parameterType="Blog" resultType="Blog">
    <bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
    SELECT * FROM BLOG
    WHERE title LIKE #{pattern}
    </select>