Node.js 博客文章搜索 API 实现 - 多字段模糊查询
exports.getSelectBlogs = (req, res) => {\n const info = req.body;\n \n const sqlStr = select * from blogs_info where id LIKE ? or title LIKE ? or author LIKE ? or classify LIKE ?;\n const searchStr = %${info.keyword}%;\n db.query(sqlStr, [searchStr, searchStr, searchStr, searchStr], (err, results) => {\n if (err) return res.cc(err);\n if (results.length === 0) return res.send({\n status: 0,\n message: "查询成功",\n data: []\n });\n res.send({\n status: 0,\n message: "查询成功",\n data: results\n });\n });\n};
原文地址: https://www.cveoy.top/t/topic/pKT7 著作权归作者所有。请勿转载和采集!