前端请求:
http://localhost:3002/api/user/login?username=002&password=002
后端响应
router.get('/api/user/login', (req, res) => {
let username = req.query.username;
let password = req.query.password;
const sqlStr = `SELECT * FROM sys_user where username= '${username}' and password='${password}'`
console.log(sqlStr)
db.query(sqlStr, (err, results) => {
// 查询数据失败
if (err) {
return console.log(err.message)
} else {
res.send({
status: 200,
message: '获取所有用户成功',
data: results,
})
}
})
})
结论:使用req.query.参数名 获取参数值
执行效果