本文介绍了Play Framework 2.x的自定义视图目录不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我很习惯使用Play Framework(2.2.x),而且我很难想出如何在 \app\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\views 目录。 我的项目组织起来,使得应用程序的每个部分(目录)都有自己的视图,控制器,服务,存储库...等等这是我想要保留的结构。它看起来像这样: \app\Game\Views \app\Game\\ \\Controllers \app\Game\Services \app\Game\Repositories \app\Players\Views \\ \\app\Players\Controllers \app\Common\Views \app\Common\Repositories ... etc 从上图可以看出,视图位于每个应用程序部分的子目录中。查看位置从一个子目录深入到更多。它看起来像这样: \app\Game\Views \app\Game\\ \\ Views\sports.scala.html \app\Game\Views\dates.scala.html \app\Game\Views\invites.scala.html \app\Common\Views\Layouts \app\Common\Views\Layouts\default.scala.html \app\\ \\Common\Views\Partials \app\Common\Views\Partials\Headers\default.scala.html \app\Common\Views\Partials \Headers\onboarding.scala.html ... etc 如果我按照一般来说,呈现位于 \app\views 中的视图的默认播放方式一切正常: views.html.index.render() 我是很难适应默认的播放方式来识别位于 \app\views 目录。我确定有一些配置或方式来识别这些视图,但是我在文档中看不到。 如何渲染视图 \app\views 目录中的不位于 感谢您的帮助解决方案你不需要太多,只是正确地解决它。 假设你在 app \common\views\index.scala.html 中看到你的观点,那么在你的控制器你必须参考 common.views.html.index 。请注意额外的常用。 您可以查看从模板生成的类的实际包, code> target / scala-2.10 / src_managed / main /< your-prefixes> / views / html / I'm new to using Play Framework (2.2.x) and I am having a tough time figuring out how to render views not located in the \app\views directory.My project is organized such that each section (directory) of the app has it's own views, controllers, services, repositories... etc. It's a structure I'd like to keep. It looks something like this:\app\Game\Views\app\Game\Controllers\app\Game\Services\app\Game\Repositories\app\Players\Views\app\Players\Controllers\app\Common\Views\app\Common\Repositories... etcViews, as you can see from above, are in sub-directories in each app section. View locations vary from one sub-directory deep to many more. It looks something like this:\app\Game\Views\app\Game\Views\sports.scala.html\app\Game\Views\dates.scala.html\app\Game\Views\invites.scala.html\app\Common\Views\Layouts\app\Common\Views\Layouts\default.scala.html\app\Common\Views\Partials\app\Common\Views\Partials\Headers\default.scala.html\app\Common\Views\Partials\Headers\onboarding.scala.html... etcIf I follow the default 'Play' way of rendering a view located in \app\views everything works fine: views.html.index.render()I'm having a tough time adapting the default 'Play' way to recognize views located outside of the \app\views directory. I'm sure there's some sort of configuration or way of identifying those views, but I just can't see it in the documentation.How do I render a view not located in the \app\views directory?Thanks for your help. 解决方案 You don't have to do much, but just address it correctly.Assume you have your view in app\common\views\index.scala.html, then in your controller you have to refer to it common.views.html.index. Note the extra common.You can check the actual packages of the classes generated from the templates by looking into target/scala-2.10/src_managed/main/<your-prefixes>/views/html/ 这篇关于Play Framework 2.x的自定义视图目录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-01 19:31