后端代码:
router.get('/check', async (ctx, next) =>{
let datt=ctx.url;
let dat=datt.replace("&","=")
let ks=dat.split("=")[1]
let js=dat.split("=")[3]
let sql="SELECT * FROM 8month_yhgcj WHERE 日期 BETWEEN ? AND ?"
db.query(sql, [ks,js],function (err, result) {
if (result.length>0) {
result = JSON.stringify(result);
console.log(result);
} else {
console.log("数据库没内容");
}
});
ctx.body = result
// console.log(result);
});
你要写道查询的里面,查询那里是异步的。 (而且为啥是ctx,和next不是res和req,是我老了吗)
[mw_shl_code=javascript,true]router.get('/check', async (ctx, next) =>{
let datt=ctx.url;
let dat=datt.replace("&","=")
let ks=dat.split("=")[1]
let js=dat.split("=")[3]
let sql="SELECT * FROM 8month_yhgcj WHERE 日期 BETWEEN ? AND ?"
db.query(sql, [ks,js],function (err, result) { ...
router.get('/check', async (ctx, next) =>{
let datt=ctx.url;
let dat=datt.replace("&","=")
let ks=dat.split("=")[1]
let js=dat.split("=")[3]
let sql="SELECT * FROM 8month_yhgcj WHERE 日期 BETWEEN ? AND ?"
db.query(sql, [ks,js],function (err, result) {
if (result.length>0) {
result = JSON.stringify(result);
console.log(result);
} else {
console.log("数据库没内容");
}
ctx.body = result
});
// console.log(result);
});