function querySql (defaultSql, params) { let querySql = defaultSql let paFlag = false for (paraName in params) { if (params[paraName]) { paFlag = true querySql = querySql + ` and ${paraName} = ${params[paraName]}` } } if (!paFlag) { querySql = defaultSql } return querySql } let sql = 'select * from user limit 0,10 where deleteFlag != 1' let params = { name: '11', sex: '男', age: '' } console.log(querySql(sql, params))