问题描述
我在Java中使用Play Framework作为网络应用程序。
I'm using the Play Framework for a web app in Java.
我想在帐户子包中放置一个帐户控制器,例如:
I'd like to put an Account controller in an "account" subpackage, for example:
|- controllers
|- account
|- Account.java
虽然我的意见组织如下:
While my views are organized like:
|- views
|- Account
|- index.html
Account.java文件包含:
The Account.java file contains:
package controllers.account;
import play.mvc.Controller;
public class Account extends Controller {
public static void index() {
render();
}
}
当请求 http:// localhost / account / {action}
时,会出现以下行为:
I'd like to have the following behavior:
重定向到 Account
文件夹中显示视图的 Account.java
控制器。
when a request is made to http://localhost/account/{action}
, it's redirected to the Account.java
controller that shows the view in the Account
folder.
任何提示?
推荐答案
您是否尝试将视图放在与控制器结构匹配的结构中?
Have you tried putting your views in a structure that matches your controller structure?
|- views
|- account
|- Account
|- index.html
除此之外,您可以随时将视图名称传递给render >
Beside that, you can always pass in the view name to the render() call:
render("Account/index.html");
我个人会永远坚持随播放提供的内置结构。否则,你可以很容易地结束重构地狱,当你重新排列你的控制器结构在路上的某处...
I personally would always stick to the built-in structure that is supplied with play. Otherwise you could easily end up in refactoring hell, when you rearrange your controller structure somewhere down the road...
这篇关于如何玩!控制器在任意子包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!