Node.js 博客文章搜索API - 使用 SQL 查询获取匹配结果
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.cc("查询失败,该文章不存在");\n res.send({\n status: 0,\n message: "查询成功",\n data: results\n });\n });\n};
原文地址: https://www.cveoy.top/t/topic/pKTv 著作权归作者所有。请勿转载和采集!