Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

定义controller,大家喜欢哪种写法?

$
0
0

定义controller,大家喜欢哪种写法?

处理get请求,就直接写一个get方法即可

class MyController extends BaseController {
  get () { 
    var a = this.query.a

    return `hello world ${a}`
  } 
}

模拟servlet,在get方法里传参数,req和res

class MyController extends BaseController {
  get (req, res) { 
    var a = req.query.a

    return res.body = `hello world ${a}`
  } 
}

大家喜欢哪种写法?


Viewing all articles
Browse latest Browse all 14821

Trending Articles