mybatis +mysql 使用like批量模糊查询方法

where CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE '%${pd.str}%'

CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE'%${item}%'

CONCAT 里面是要查询的数据库字段 使用ifnull是为了规避null的风险,foreach 循环 collection要循环的list 

item-自定义名称 , index -下标 , 以open开始 ,close结束 , separator中间间隔符号 

遍历结果为:

CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE '%"二年级语文试题"%'
or  
CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE'%二年级%'
or 
CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE'%语文%'
or 
CONCAT(IFNULL(a.title,''),IFNULL(a.description,''),IFNULL(a.keywords,'')) LIKE'%试题%'

你可能感兴趣的:(java笔记)