gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:27:41 25 4
gpt4 key购买 nike

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

现在我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com