如何把玩!任意子包中的控制器 [英] How to put Play! controllers in an arbitrary sub-package

查看:21
本文介绍了如何把玩!任意子包中的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Java 网络应用中使用 Play 框架.

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} 发出请求时,它会被重定向到 Account.java 控制器,该控制器在 http://localhost/account/{action} 中显示视图code>Account 文件夹.

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

这篇关于如何把玩!任意子包中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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