创建一个Controller,名称为:HelloController
在项目目录下,在命令行中输入以下命令
PS D:\workspace\nodejs\pj_hell> node ace make:controller HelloController -e
CREATE: app\Controllers\Http\HelloController.ts
命令执行后生成控件器文件如下图所示:
添加一个hello 方法 :
export default class HelloController {
async hello(){
return "hello world";
}
}
在路由文件/start/routes.ts中配置访问路由:
Route.get('/hello',"HelloController.hello");
启动项目,在浏览器中访问 http://127.0.0.1:3333/hello
adonisjs的HelloWord程序完成!