第一种方式:标红的那句,由于jfinal中的paginate方法,不支持having,故外面包了一层
select * from (SELECT
t1.*,
t2.`name` companyName
FROM
npro_product t1
LEFT JOIN sys_company t2 ON t1.com_id = t2.id
where t1.is_deleted=0
#if(pro_years!=null &&pro_years.trim() != '')
AND t1.pro_years =#para(pro_years)
#end
#if(com_id!=null &&com_id.trim() != '')
AND t2.id =#para(com_id)
#end
GROUP BY t1.id
#if(pro_name != null && pro_name.trim() != '')
having instr(t1.pro_name, #para(pro_name.trim()) )
#end
) alias
ORDER BY create_time desc
第二种方式:
if (StrKit.notBlank(industry)) {
sql.append(" AND t1.industry IN ( SELECT id FROM pro_catgory c WHERE flag = 2 and c.`name` LIKE ? ) ");
parasList.add("%"+industry+"%");
}
在网上找了找博客有的针对单独的是这样写的
':用于包裹搜索条件,需转为\';
%:用于代替任意数目的任意字符,需转换为\%;
_:用于代替一个任意字符,需转换为\_;
\:转义符号,需转换为\\\\。
以下是一些匹配的举例。
SELECT * FROM `table` WHERE `title` LIKE 'a\'b%'; -- 搜索a'b...
SELECT * FROM `table` WHERE `title` LIKE 'a\%b%'; -- 搜索a%b...
SELECT * FROM `table` WHERE `title` LIKE 'a\_b%'; -- 搜索a_b...
SELECT * FROM `table` WHERE `title` LIKE 'a\\\\%'; -- 搜索a\b...