Skip to content

Commit

Permalink
feat(param): query
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawei397 committed Jul 5, 2021
1 parent 16d60d5 commit 9e438ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions example/router/role.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, createParamDecorator, Get, Post, Headers } from "../../mod.ts";
import { Body, Controller, createParamDecorator, Get, Post, Headers, Query } from "../../mod.ts";
import { Context } from "../deps.ts";

function add() {
Expand All @@ -16,13 +16,14 @@ function add() {
@Controller("/role")
export class RoleController {
@Get("/info/:id")
test(context: Context, @add() name: string) {
test(context: Context, @add() name: string, @Query() params: any) {
console.log(params);
context.response.body = "role info " + name;
}

@Post("/info")
info(context: Context, @add() name: string, @Body() params: any, @Headers() headers: any) {
console.log('ctx', name, params, headers);
console.log('ctx', context, name, params, headers);
context.response.body = "role info " + name;
}
}
8 changes: 8 additions & 0 deletions src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export function Body() {
// console.log('value', value);
return value;
}
});
}

/**
* 只对GET请求生效
*/
export function Query() {
return createParamDecorator((ctx: Context) => {
return (ctx as any).params;
});
}
Expand Down

0 comments on commit 9e438ce

Please sign in to comment.