【发布时间】:2021-03-03 06:49:44
【问题描述】:
假设你有一个这样的界面:
import { Get, QueryParam } from 'routing-controllers';
// ...
@Get('/students')
async getStudents(
@QueryParam('count') count?: number,
): Promise<void> {
console.log(count);
}
例如,您如何确保 count 是 int 而不是 float?这样的事情是无效的:
@IsInt() @QueryParam('count') count?: number,
IsInt 只能用于类属性,例如用于身体模型,不能用于单个参数值。但根据。这个https://github.com/typestack/routing-controllers#auto-validating-action-params有可能:
这种技术不仅适用于@Body,也适用于@Param, @QueryParam、@BodyParam 和其他装饰器。
【问题讨论】:
-
Number.isInteger (count)
标签: node.js rest routing-controllers