前言
数据全等查询:皮卡猪
数据左模糊查询 :*卡猪
数据右模糊查询:皮卡*
数据全局模糊查询: 卡
/**
* 通用模糊查询语句
* @param searchContent 模糊查询json对象字符串,如下示例
* searchContent: {"maskSearch:"123",fieldSearch:"column_name"}"
* @param mode 模糊查询模式,默认right,以右边做模糊查询;mode:left,right,其他全部默认左右的模糊查询
* @returns {string}
*/
fuzzyQueryWhere : function (searchContent, mode = 'right') {
let where = "";
//模糊内容查询
//判断字段是否为空
if (searchContent != null &&searchContent.maskSearch !=null) {
//清除前端入参左右空格
searchContent.maskSearch = common.stringHelper.trim(searchContent.maskSearch);
if (mode == 'right') {
where += ` and ${searchContent.fieldSearch} like '${searchContent.maskSearch}%'`;
}
else if (mode == 'left') {
where += ` and ${searchContent.fieldSearch} like '%${searchContent.maskSearch}'`;
}
else if (mode == 'no_contain') {
where += ` and ${searchContent.fieldSearch} = '${searchContent.maskSearch}'`;
}
else {
where += ` and ${searchContent.fieldSearch} like '%${searchContent.maskSearch}%'`;
}
}
return where;