0

URL を 2 つの 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 を許可しません (それを機能させるためのトリックがあります - しかし、私はそのルートには行きたくありません - 不必要に複雑です)。

助けに感謝します。私はかなりのグーグルをしました。

4

2 に答える 2

1

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){
  //...
}
于 2017-02-02T09:55:44.683 に答える