我正在为 Java 网络应用程序使用 Play 框架。
我想将一个帐户 Controller 放在一个“帐户”子包中,例如:
|- controllers
|- account
|- Account.java
虽然我的观点是这样组织的:
|- views
|- Account
|- index.html
Account.java 文件包含:
package controllers.account;
import play.mvc.Controller;
public class Account extends Controller {
public static void index() {
render();
}
}
我想要以下行为:
当向 http://localhost/account/{action}
发出请求时, 它被重定向到 Account.java
在 Account
中显示 View 的 Controller 文件夹。
有什么建议吗?
最佳答案
如果您确实创建了一个包结构,请注意有一些新语法并不明显:
Controller 的反向查找
将包名放在'controllers'和'routes'之间:
controllers.account.routes.Account.index
例如在 View 中
<a href="@controllers.account.routes.Account.index" class="btn">Exit</a
在 Controller 中查看引用
包名称遵循“views.html”:
return ok(views.html.account.index.render());
关于java - 如何放玩!任意子包中的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6499078/