需求:一个搜索框同时对userId和title进行模糊查询。
第一次:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
![日志里的SQL是这样的](https://img-blog.csdn.net/20160707230448959)这种方式查询时,日志里的SQL如上所示,会导致对2个字段进行AND查询,只有都具有相同关键字时才可以被查出来。
*
第二次:
*
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
在日志中会出现如上图所示的错误,很明显,userId字段前多了“and”,TITLE前应该为“or”。
第三次:
“
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
trim标签中不要条件字段,只在 第一个以后的字段前加“or”即可。
好了!