Node.js 博客搜索 API 代码示例:根据标题、作者、分类等关键字查询
exports.getSelectBlogs = (req, res) => { const info = req.body;
const sqlStr = `select * from blogs_info where title LIKE ? or author LIKE ? or classify LIKE ?`;
const searchStr = `%${info.keyword}%`;
db.query(sqlStr, [searchStr, searchStr, searchStr], (err, results) => {
if (err) return res.cc(err);
if (results.length === 0) return res.send({
status: 0,
message: '查询成功',
data: []
});
res.send({
status: 0,
message: '查询成功',
data: results
});
});
};
原文地址: https://www.cveoy.top/t/topic/pKUF 著作权归作者所有。请勿转载和采集!