作业
来源:3-5 CLI初试:启动 Nest 应用程序 + 创建控制器
天才民啊
2022-12-06
import { Controller, Get, Param } from '@nestjs/common';
import { RangeService } from './range.service';
@Controller('range')
export class RangeController {
constructor(private rangeService: RangeService) {}
@Get(':num')
getRangeInfo(@Param() param) {
return this.rangeService.getRangeInfo(param);
}
}
import { Injectable } from '@nestjs/common';
@Injectable()
export class RangeService {
getRangeInfo({ num }): any {
if (isNaN(num)) return { code: 201, data: null, msg: '参数错误' };
const arr: string[] = [];
for (let i = 1; i <= num; i++) {
arr.push(String(i));
}
return { code: 200, data: arr, msg: '请求成功' };
}
}
写回答
1回答
-
Brian
2022-12-09
上道了,加油小伙伴~~~~
继续往后看吧~~
还有可以优化的地方哦~~学一下DTO相关的章节~Filters过滤器章节
00
相似问题