Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playframework2 like reverse routing in spring

Can Anyone can advice me routing mechanism in spring.

I use thymeleaf for my view and I would like to use class names and method names for my url in views- just like in playframework.

But I like in spring that I define url before the controller method declaration.

Whaitting for Your sugestion. Thanks.

like image 380
masterdany88 Avatar asked Aug 15 '26 18:08

masterdany88


1 Answers

Since version 4.1, Spring Framework provides a way to generate routes to resources from templates (i.e. reverse routing in views).

You can check the reference documentation on the subject, but it's basically using auto-generated named routes for that.

I don't know if Thymeleaf supports this in its standard dialect, but you could quite easily extend it; if not, this is probably a feature that could be contributed to the Thymeleaf project.

Let's say you have a MyUserController like this:

@Controller
public class MyResourceController {

  @RequestMapping("/user/{name}")
  public String showUser(String name, Model model) {

    ...
    return "show";
  }
}

With such a dialect, you could then refer to an action like this:

<a th:uri="mvcUrl('MRC#ShowUser').buildAndExpand('bob')">Show user Bob</a>
<!-- will generate "/user/bob" -->
like image 70
Brian Clozel Avatar answered Aug 17 '26 12:08

Brian Clozel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!