如何映射具有两个ID的网址:
/ orders / $ id1 / orderlines / $ id2
id2是可选的
/ orders / $ id1 / orderlines GET->订单ID1的所有订单行
/ orders / $ id1 / orderlines / $ id2 GET->在订单ID1中显示订单行ID2
这些方法将映射到OrderLineController
使用Spring MVC @RequestMapping和@PathVariable非常容易。
Grails 3不允许@RequestMapping(有一些技巧可以使它工作-但我不想走那条路线-不必要地复杂)。
感谢帮助。我做了很多谷歌搜索。
最佳答案
您可以使用UrlMappings:
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/orders/$id1/orderlines"(controller: 'orderLine', action: 'someAction1')
"/orders/$id1/orderlines/$id2"(controller: 'orderLine', action: 'someAction2')
}
}
OrderLineController.groovy
def someAction1(Long id1){
//...
}
def someAction2(Long id1, Long id2){
//...
}
关于grails - Grails 3网址映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41993566/