import UserService from 'services/UserService.js'; import Router from 'utils/router.js'; class UserController { static routes() { let router = new Router({ prefix: '/api' }); router.get('/hello', UserController.hello); router.get('/user/:id', UserController.getUser); return router; } static async hello(ctx) { ctx.body = 'Hello World'; } static async getUser(ctx) { // 调用 service 层获取用户 const user = await UserService.getUserById(ctx.params.id); ctx.body = user; } } export default UserController;