mysql+koa 模糊查询

428 阅读1分钟
// 分类搜索
let searchCategory = (category) => {
  let _sql = `select * from categories where category like "%${category}%";`
  return query(_sql)
}
router.get('/categorySearch/:category',async(ctx,next) => {
    let category = ctx.params.category;
    console.log(category)
    await userModel.searchCategory(category)
        .then(result => {
            console.log(result)
            ctx.body = {
                code: 200,
                msg: '删除成功',
                data: result
            }
        })
})

query查询

params查询