binding - 在 Route 中使用 Play Framework : Reverse routing 中的对象

标签 binding routing playframework symfony-1.4

是否可以生成由对象映射的 url?
Pojo Object Mapping是 PlayFramework (1.2.2) 的原生函数,但是 呢?反向路由 ?

我想这样做:

java :

class MyControler extends Controller {
    public static function myAction(MyObject o) {}
}

路线:(像这样?如果可能的话,我不知道这样做的语法!)
GET    /folder/{myObject.name}/{myObject.id}      MyController.myAction(myObject)

模板 :
<a href="@{MyControler.myAction(myObject)}">Go</a>

预期结果 :
<a href="/folder/xxNamexx/33">Go</a> 

(我有 Symfony 背景,我搜索了一个等效于 Object Route Class 的内容)

我觉得玩!不支持这个功能,有人可以证实或反驳这个想法吗?
谢谢你。

最佳答案

你所要求的目前是不可能的。

所以通常的解决方法是这种模式:

GET     /folder/{id}            MyController.myAction

class MyController extends Controller {
    public static void myAction(Long id) {
        MyObject o = MyObject.findById(id);
        // You may probably want to add the following line:
        notFoundIfNull(o);
        // … then your code here
    }
}

解决方案不是那么冗长,但我同意 Play 的进一步版本!应该允许更简单的语法,类似于您的建议。

关于binding - 在 Route 中使用 Play Framework : Reverse routing 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7058518/

相关文章:

c# - XAML - 为什么数据绑定(bind) TwoWay 不适用于 .net 4.0 中组合框的文本属性?

具有命名路由器导出 : ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL 段的 Angular 辅助路由

asp.net - 你能确定你的网络表单页面遵循的路线名称吗?

java - 如何重定向到在 play 框架中有 post 方法的 Action

php - PDO 绑定(bind) n 次与 foreach 相同的值

python - tkinter:将鼠标滚轮绑定(bind)到滚动条

wpf - 如何从在父容器上注册的 MouseLeftButtonUp 事件中获取单击的对象?

scala - 更改 Play IsAuthenticated 中的身份验证方法

scala - Play Framework scala如何创建临时变量

objective-c - 不使用 NSMatrix 的 Cocoa 单选按钮可以绑定(bind)吗?