1.用:id方式写在路径上(不常用)
router.get('/user/:id', ctx => {
ctx.body = ctx.params.id//2222
})
请求
http://localhost:8080/2222
当遇到参数和路径想混时,如下
//当参数和路径相混时,谁在前面,执行谁,不再向后执行,除非有next(),才会向后执行
router.get('/user/1', async (ctx, next) => {
ctx.body = "aaa"
// aaa会被覆盖
//await next();
})
router.get('/user/:id', ctx => {
ctx.body = "bbb"
})
谁在前面,执行谁,不再向后执行,除非有next(),才会向后执行
2.用 ? 加参数a=111
router.get('/user/', ctx => {
ctx.body = ctx.query.id//222
})
请求
http://localhost:8080?id=222