Play Framework Routing with Multiple Settings

I'm trying to set up an SEO friendly route on Play! Framework, which has several parameters (the second parameter is optional). I aim at:

http://domain.com/article/jsmith/name-of-article

But the game is generated:

http://domain.com/article/jsmith?articleSlug=name-of-article

In my opinion: @{Article.show("jsmith","name-of-article")}

My controller
public static void show(String username,String articleSlug){ ... }

My route file

GET / article / {username} Article.show
GET / article / {username} / {articleSlug} Article.show
+5
source share
2 answers

It seems your pattern matches the first route. Reversing an order will lead to a trick,

GET /article/{username}/{articleSlug}    Article.show
GET /article/{username}                  Article.show

, articleSlug.

show(username, articleSlug){}
+3

, , :

:

GET     /{<[0-9]+>id}/{slug}            Listing.show
GET     /{<[0-9]+>id}                   Listing.show

:

public static void show(Long id, String slug) { /* ... */ }
public static void show(Long id) { /* ... */ }

:

#{a @Listing.show(item.id, item.title.slugify())}link title#{/a}
#{a @Listing.show(item.id)}link title#{/a}
0

All Articles