定义Controller

Controller的定义方式与EggJS一致

src/module-vendor/test-party/backend/src/controller/kitchen-sink/guide.js

  1. 1module.exports = app => {
  2. 2
  3. 3 class GuideController extends app.Controller {
  4. 4
  5. 5 async echo() {
  6. 6 const message = 'Hello World';
  7. 7 this.ctx.success(message);
  8. 8 }
  9. 9
  10. 10 }
  11. 11
  12. 12 return GuideController;
  13. 13};

注册Controller

src/module-vendor/test-party/backend/src/controllers.js

  1. 1const testKitchensinkGuide = require('./controller/kitchen-sink/guide.js');
  2. 2
  3. 3module.exports = app => {
  4. 4 const controllers = {
  5. 5 testKitchensinkGuide,
  6. 6 };
  7. 7 return controllers;
  8. 8};

通过controllers.js注册的Controller,系统会自动注册为Bean组件,并有如下约定:

注册名称 场景 所属模块 global beanFullName
testKitchensinkGuide controller test-party false test-party.controller.testKitchensinkGuide