Egg: RESTful 风格的 URL 定义: 请问删除多个业务是没有设计自动对应的controller里方法的命名吗?

Created on 27 Dec 2017  ·  2Comments  ·  Source: eggjs/egg

按照官网的RESTful URL约定,可以通过router.resources()统一匹配到controller的方法
image
image
现在我遇到的问题,比如删除多个,我设计的路由如下:
router.delete('/api/role', controller.role.removes) =>实现传入用户选中的要删掉的数组,一次性删除
Controller:
image
Service:
image

但接口测试 router.resources('role', '/api/role', controller.role)
http://localhost:7001/api/role DELETE ID[]
无法自动对应到removes方法上。
image

想知道是EGG没有设计删除多个这个业务所自动匹配的命名规则像图一表格中规定的那几个业务,还是我哪里写错啦!!!

Most helpful comment

如果是没有设计如上传多个或删除多个 这样的匹配场景
路由共存也是可以的
router.delete('/api/role', controller.role.removes)
router.resources('role', '/api/role', controller.role)

All 2 comments

如果是没有设计如上传多个或删除多个 这样的匹配场景
路由共存也是可以的
router.delete('/api/role', controller.role.removes)
router.resources('role', '/api/role', controller.role)

这个没有特别标准的 api 设计,所以不做,你可以自己去扩展

Was this page helpful?
0 / 5 - 0 ratings