«

QueryWrapper添加括号嵌套查询

时间:2024-5-15 16:21     作者:紫琪软件工作室     分类: mybatis-plus


//QueryWrapper添加括号嵌套查询

QueryWrapper condition = new QueryWrapper();
condition.isNull("pid");
if(!StringUtil.isEmpty(keyword)) {
condition.and(
QueryWrapper -> QueryWrapper.like("dic_key", keyword)
.or().like("dic_cn_value", keyword)
.or().like("dic_en_value", keyword)
);

}

-------结果SQL:

SELECT id,pid,dic_key,dic_cn_value,dic_en_value,create_date,update_date,status,is_del

FROM sys_dictionaries

WHERE (is_del = ? AND pid IS NULL

AND (dic_key LIKE ? OR dic_cn_value LIKE ? OR dic_en_value LIKE ?)

)
ORDER BY create_date DESC LIMIT ?