定义Controller
Controller
的定义方式与EggJS
一致
src/suite-vendor/test-party/modules/test-party/backend/src/controller/kitchen-sink/guide.js
- 1module.exports = app => {
- 2
- 3 class GuideController extends app.Controller {
- 4
- 5 async echo() {
- 6 const message = 'Hello World';
- 7 this.ctx.success(message);
- 8 }
- 9
- 10 }
- 11
- 12 return GuideController;
- 13};
注册Controller
src/suite-vendor/test-party/modules/test-party/backend/src/controllers.js
- 1const testKitchensinkGuide = require('./controller/kitchen-sink/guide.js');
- 2
- 3module.exports = app => {
- 4 const controllers = {
- 5 testKitchensinkGuide,
- 6 };
- 7 return controllers;
- 8};
通过controllers.js
注册的Controller,系统会自动注册为Bean组件,并有如下约定:
注册名称 | 场景 | 所属模块 | global | beanFullName |
---|---|---|---|---|
testKitchensinkGuide | controller | test-party | false | test-party.controller.testKitchensinkGuide |
评论: