java - play2 调用子模块中的 Controller 、模型、 View

标签 java namespaces routes playframework-2.0 sbt

尝试将我的项目拆分为几个子模块。 我创建了子模块: /模块/通用 /模块/购物

现在我正在尝试将 namespace 转换为新的 namespace ,包括新的结构。

我的 Controller :

package controllers.common;
public class Index extends Controller {}

我的模型:

package models.common;
@Entity
public class AppMode {}

我的观点:

@(AppModeForm: Form[models.common.AppMode], CurrentMode: Boolean)
 @helper.form(common.routes.CMS.appModeSubmit, 'id -> "form") {}

而且我总是遇到错误。 F.e: View 中出现错误:

reference to common is ambiguous; it is imported twice in the same scope by import controllers._ and import models._


[error] /home/kd/Application/modules/common/app/views/CMS/AppModeView.scala.html:9: reference to common is ambiguous;
[error] it is imported twice in the same scope by
[error] import controllers._
[error] and import models._
[error]                     @helper.form(common.routes.CMS.appModeSubmit, 'id -> "form") {
[error]                                  ^
[error] one error found

最佳答案

modelscontrollers 会自动导入到 Play 模板中,因此这会导致问题,您要么不必将它们命名为相同的名称,(例如将包结构围绕 common.{models,controllers} ,然后从那里显式导入你想要的东西。当然,由于可能有不止一个称为路由的东西,你仍然会遇到一些重载问题(但是您可以通过重命名为当前范围导入的内容来解决此问题,如下所示:

@import controllers.common.{routes => commonRoutes}

@helper.form(commonRoutes.CMS.appModeSubmit, 'id -> "form") 

一个更简单的选择是直接指定包,如下所示:

@helper.form(controllers.common.routes.CMS.appModeSubmit, 'id -> "form") 

关于java - play2 调用子模块中的 Controller 、模型、 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25842651/

相关文章:

java - php 的非 flash 多文件上传

c++ - 导入命名空间和导入全局命名空间的 C 函数之间发生冲突

asp.net-mvc - 通过方法属性进行 ASP.NET MVC 路由

c# - 带有扩展的 ASP.NET Webforms 路由

java - Google App Engine 不保存类中的对象列表

java - Sqlite使用ListView插入数据

java - 为具有前缀 "has"的 boolean 成员编辑 lombok getter 方法名称

Python 命名空间混淆

Python 类和命名空间?

javascript - 导致 404 的基本 nodejs 路由