gpt4 book ai didi

mysql - 不能让你的两个或多个方法在同一条路线上

转载 作者:行者123 更新时间:2023-11-30 21:40:19 26 4
gpt4 key购买 nike

项目链接 https://github.com/Kammikazy/project我无法在同一条路线上获得两种或多种方法我有密码 404我使用 mysql nodejs 和 express我的代码
Controller 联盟

const User = require('../models/Alliances')

const findAlianca = async (connection, req, res) => {

const Allianca = await User.find(connection, req.session.user.username)
if (!Allianca) {
res.status(404).send('Nenhuma cidade encontrada.');
return;
}
console.log("dddd");
req.session.Allianca = Allianca
res.locals.Allianca = Allianca
res.render('Administration/Alliances')
}

module.exports = {
findAlianca
}

路线联盟

const express = require('express')
const router = express.Router()
const connection = require('../../Config/database')
const controllerAdmin = require('../../controllers/Administration')
const controlleruser = require('../../controllers/Alliances')
router.get('/Administration/Alliances', (req, res) => controllerAdmin.findcidade3(connection, req, res))
router.get('/Administration/Alliances/limitado', (req, res) => controlleruser.findAlianca(connection, req, res))


module.exports = app => app.use('/', router)

模特联盟

const find = (connection,username) => { 返回新的 promise ((解决,拒绝)=> { connection.query(SELECT alianca.nome,alianca.N_membros,alianca.TAG FROM user INNER JOIN alianca ON user.cod_alianca=alianca.id WHERE user.username='${username}', (错误, 结果) => { 如果(错误){ 拒绝(错误) }别的{ 解决(结果) } }) })

    module.exports = {
find
}

联盟. Jade

extends layout
block title
.col-xs-6.col-xs-offset-3.col-sm-6.col-sm-offset-3
.col-sm-4(style='width:76%')
div.panel.panel-primary(style='height:50px') Alliances Page
div.panel.panel-primary(style='height:700px') fdssdklfsdklfjskldfjkldsjfl
if locals.user.cod_alianca==null
p You Dont Have Alliances
else
br
span Your Aliance
span= locals.Allianca.nome
.col-xs-2.panel-red(style='width:24%;height:100%;text-align:center')

我的应用

require('./routes/Administration/Alliances')(app)

我的连接数据库

const mysql = require('mysql')
const config = require( "./config.json" )
const connection =mysql.createConnection({
host:config.host,
user:config.user,
password:config.password,
database:config.database,
// port:config.port
});

connection.connect((err) =>{
if(err){
console.log(err)
process.exit(0)
}else{
console.log('database on')
}
})

我做错了什么,我找不到解决问题的方法

最佳答案

不确定你在问什么,但是如果你想在同一路由/API 中调用多个函数,你可以执行以下操作:

使用 expressJs,您可以使用 next 函数,例如:

app.get('/Administration/Alliances', (req, res, next) => { 
//Do something here and to add data to your request use
req.body.newData = 'newData';
//after this just call next function
next();
}, (req, res, next) => {
//Can continue this cycle of calling next function until last `sendResponse` function is reached.
//Can even set `error` in request for `sendResponse`
req.error = "Some error";
next();
}, (req, res) => {
if(req.error) {
res.status(400).send(req.error);
} else {
res.status(200).send(req.body.result);
}
});

关于mysql - 不能让你的两个或多个方法在同一条路线上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51957697/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com