前言:本来想用Node做后端,vue-element-admin做前端来练习一下技术,了解一下开发的过程
// 用户登录处理函数
exports.login = (req, res) => {
    console.log(req.body)
    const userinfo = req.body
    const sql = `select * from user where username=?`
    database.query(sql, userinfo.username, function(err, results) {
        //  执行sql语句失败
        if (err) return res.cc(err)
            // 执行sql语句成功,但是查询到的数据条数不等于1
        if (results.length != 1) return res.cc("登录失败啊")
            // 拿着用户输入的密码,和数据库中存储的密码进行对比
        if (userinfo.password === results[0].password) {
            // 生成 Token 字符串
            const tokenStr = jwt.sign(userinfo, config.jwtSecretKey, {
                expiresIn: '10h', // token 有效期为 10 个小时
            })
            res.send({
                status: 200,
                messgae: '登录成功',
                token: 'Bearer ' + tokenStr,
            })
        } else {
            return res.cc('登录失败')
        }这是登录的核心后端代码,用户登录后和数据库进行对比,从而校验密码的正确与否,在前端vue-element-admin调用后发生了ValidationError: "username" is required,但是起先在postman我已经测试过接口的可行性,
 在form-data类型中调用接口也会发生相同的错误,但是在x-www-form-urlencoded类型中调用接口不会发生错误,随机我便想起了
通过设置header来修改提交数据的类型,但是经过测试扔不可行 ,随后我想起了qs

经过测试后即可解决问题 
 


![[SSM]MyBatis基础](https://img-blog.csdnimg.cn/56b0e3df2ca7447b980f4d866c37a384.png)
















