当前位置:网站首页>Controller-----controller
Controller-----controller
2022-08-05 08:10:00 【cjx177187】
Controller负责解析用户的输入,处理后返回响应的结果.1.所有的Controller 文件都必须放在 app/controller目录下2.支持多级目录,访问时可以通过目录名级联访问.
作用:
- Accepts parameters provided by the user,Then look up the parameters from the database and return them to the user
- 根据用户访问的URlDifferent then renders a different template
- 代理服务:Return the user's request to other servers
模板语法:
//严格模式
'use strict';
//引入egg中Controller属性
const Controller = require('egg').Controller;
//继承Controller这个类
class HomeController extends Controller {
async index() {
const { ctx } = this;//上下问对象
ctx.body = 'hi, egg';
}
}
//导出Controller
module.exports = HomeController;
如果路由是:
router.get('/hello', controller.user.news)
The controller corresponds:
在controller文件夹下有一个user文件中有一个news方法
如果路由是:
router.get('/hello', controller.user.home.news)
The controller corresponds:
在controller文件夹下有一个user文件夹下有一个home文件中有一个news方法
anyn Any type of data can be entered into the function,He will convert himselfJSON数据
this.ctx就是controllerThe provided functions are mainly provided by using it:给前端发送数据,Access plugin functionality
this.ctx.body="hello"====>It will only be executed once and then disconnected
可以再controllerCreate a new one in the folderjs文件,实现模块化
边栏推荐
猜你喜欢

Redis implements distributed lock-principle-detailed explanation of the problem

微信 小程序 之PC端 不支持 wx.previewMedia 方法 故用自定义轮播图进行 模拟照片视频的播放

DataFrame在指定位置插入行和列

MobileNetV1架构解析

吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)

Ethernet Principle

The Coolest Kubernetes Network Solution Cilium Getting Started Tutorial

v-if/v-else determines whether to display according to the calculation

unity 头发的渲染

TensorFlow安装步骤
随机推荐
CROS和JSONP配置
Chapter 12 贝叶斯网络
高效使用数码相机的诀窍
【无标题】长期招聘硬件工程师-深圳宝安
MobileNetV2架构解析
D2--FPGA SPI interface communication2022-08-03
ps怎么把图片变清晰,自学ps软件photoshop2022,简单快速用ps让照片更清晰更有质感
【结构体内功修炼】结构体实现位段(二)
8.4模拟赛总结
SVG星球大战样式Toggle切换开关按钮
线性代数对角化
EA谈单机游戏:仍是产品组合中极其重要的部分
青苹果论坛重新开放
力扣每日一题
爬虫从入门到入牢
php fails to write data to mysql
图扑软件与华为云共同构建新型智慧工厂
moment的使用
pnpm 是凭什么对 npm 和 yarn 降维打击的
基于多块信息提取和马氏距离的k近邻故障监测