var nn="";
module.exports = async (ctx, next) => {
var data = ctx.request.query.ID;
var sql = ‘SELECT * FROM facility WHERE id=’+data;
connection.query(sql, function (err, result) {
if (err) {
console.log(’[SELECT ERROR] - ', err.message);
}
nn = result[0];
// ctx.response.body = nn;
console.log(’--------------------------SELECT----------------------------’);
console.log(result);
console.log(’------------------------------------------------------------\n\n’);
});
ctx.body = nn;
}
要编译两次才能显示结果,看到好像因为异步的关系但不会改