【发布时间】:2020-04-29 23:00:54
【问题描述】:
我在文件 entry.routes.js 中的位置有以下命令:/nodejs-express-mysql/app/routes
app.get("/energy/api/ActualvsForecast/:AreaName/:Resolution/date/:Year-:Month-:Day/format=:Type", entry.findFourteen);
我还在 entry.controller.js 文件中的位置编写了以下代码:/nodejs-express-mysql/app/controllers
exports.findFourteen = (req, res) => {
Entry.findByPars13(req.params.AreaName,req.params.Resolution,req.params.Year,req.params.Month,req.params.Day,req.params.Types, (err, data) => {
if (err) {
if (err.kind === "not_found") {
res.status(404).send({
message: `Not found Entry with AreaName ${req.params.AreaName}. Five`
});
} else {
res.status(500).send({
message: "Error retrieving Entry with AreaName " + req.params.AreaName
});
}
} else{
if(req.params.Type=="csv"){
message:"This is csv and the format is: " +req.params.Type
res.send(data);
}
else if (req.params.Type=="json"){
message:"This is json and the format is: " +req.params.Type
res.send(data);
}
}
});
};
我想在 csv 和 json 的 ifs 中编写一些命令,这样如果用户将格式指定为 csv,它就会以 csv 格式返回数据。 json 作为默认值返回,所以如果我认为不应该这样做,内部会发生变化。我怎么能这样做?
【问题讨论】: