Playframework2像春天的反向布线 [英] Playframework2 like reverse routing in spring

查看:91
本文介绍了Playframework2像春天的反向布线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以在春季建议我路由机制。

Can Anyone can advice me routing mechanism in spring.

我在视图中使用thymeleaf,并且在视图中使用类名和方法名作为url -就像在playframework中一样。

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.

但是我喜欢在春季在控制器方法声明之前定义url。

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

等待您的建议。

推荐答案

从4.1版开始,Spring Framework提供了一种从模板生成到资源的路由的方法(即视图中的反向路由)

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.

我不知道Thymeleaf是否在其标准方言中支持此功能,但是您可以很容易地对其进行扩展

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.

假设您有一个MyUserController,如下所示:

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" -->

这篇关于Playframework2像春天的反向布线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆