如何解决邮递员未收到有关我的属性的帖子数据
我以前使用过 Postman,它通常在我测试来自我的 MERN 项目的路由时有效。然而,post 请求并没有在 Postman 窗口的底部显示我的属性(姓名和职位),它只显示了 id、created_at 和 updated_at 属性。
这是我的代码
运动员.model.js
const AthleteSchema = new mongoose.Schema({
name: { type: String },position: { type: String }
},{ timestamps: true });
module.exports.Athlete = mongoose.model('Athlete',AthleteSchema);
athlete.controller.js
const { Athlete } = require('../models/athlete.model');
module.exports.index = (request,response) => {
response.json({
message: "Hello World"
});
}
module.exports.createAthlete = (request,response) => {
console.log('create method executed.')
const { name,position } = request.body;
Athlete.create({
name,position
})
.then(athlete => response.json(athlete))
.catch(err => response.json(err));
}
athlete.routes.js
const AthleteController = require('../controllers/athlete.controller');
module.exports = function(app){
app.get('/api',AthleteController.index);
app.post('/api/athletes',AthleteController.createAthlete);
}
任何帮助都将不胜感激!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。