子模块中的play2调用控制器,模型,视图 [英] play2 calling controllers, models, views in submodule

查看:100
本文介绍了子模块中的play2调用控制器,模型,视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将我的项目拆分为几个子模块. 我创建了子模块: /modules/common /modules/shopping

Trying to split my project to few submodules. I've created submodules: /modules/common /modules/shopping

现在我正在尝试将名称空间转换为包括新结构的新名称空间.

Now I am trying convert name spaces to new one including new structure.

我的控制器:

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: 视图错误:

And I am getting errors all the time. F.e: an error in 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会自动导入到播放模板中,因此这会导致问题,您要么不必将它们命名为相同的名称,(例如,将包结构转为common.{models, controllers},然后从那里显式导入所需的内容.当然,由于可能有不止一个称为路由的东西,所以您仍然会遇到一些重载问题(但是您可以通过重命名来解决此问题)像这样导入当前范围:

models and controllers are automagically imported into the play templates, so this causes the problem, you would either have to not name them the same, (for example turn the package structure around to common.{models, controllers} and then explicitly import what you want from there. Of course since there might be more than one thing called routes you would still have some problems with overloading (but you can workaround by renaming things you import for the current scope like this:

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

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

一个更简单的选择是仅显式指定软件包,如下所示:

An easier option would be to just explicitly specify the package, like this:

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

这篇关于子模块中的play2调用控制器,模型,视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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