繁体   English   中英

如何在Play Framework 2.3中从我的表单反向路由到操作

[英]How to reverse route to an action from my form in Play Framework 2.3

今天是个好日子,

我是Play框架的新手,正在尝试开始构建应用程序。 app/controllers文件夹下,我创建了子包,因此我有一些类似于app/controllers/products/ProductController.class

在我的routes.conf文件中,我添加了这样的示例路由

GET /createproduct controllers.products.ProductController.listAllProducts() POST /createproduct controllers.products.ProductController.createProductDetail()

我可以转到URL http://localhost:9000/createproduct并查看我创建的示例视图。

我现在的问题是我想向视图中添加表单,并且当我尝试使用表单助手方法将数据从我的新视图中发布到上述POST URL时,如下所示

@helper.form(action = routes.products.ProductController.createProductDetail()) {

我得到的错误

value products is not a member of object controllers.routes

我在网上看到的所有示例仅使用route.Application示例,这不适合我的问题。

所以我的问题是我该如何反向路由到该操作或使用表单帮助程序从视图反向路由

有效语法为:

[full-package-name].routes.[controller].[method]

所以你的情况应该是

 controllers.products.routes.ProductController.createProductDetail()

controllers.routes是隐式导入的,因此要与默认包中的控制器一起使用,可以将其缩写为:

routes.Controller.action()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM