Play Framework [2.4.x]如何解决子模块的路由文件中的公共资产 [英] Play Framework [2.4.x] how to address public assets in a sub module's routing file

查看:100
本文介绍了Play Framework [2.4.x]如何解决子模块的路由文件中的公共资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于当前的讨论,此先前的问题可以用作子模块"的含义的基线:

This previous question may serve as a baseline for what "submodules" mean for the purpose of the current discussion: Play Framework [2.4.x] Working with Sub Modules

如果您了解Play子模块,那么在该上下文下,如何在子模块上输入路由条目以公开公共"文件夹中的资产?

If you understand a Play submodule then given that context how does one enter the routing entry on the submodule to expose assets from a "public" folder?

每当我尝试进行基本输入时(如下所示),我的整个根模块都无法编译一条路由,但是我没有收到可用"错误或其他可能发生的指示.

Whenever I attempt to make a basic entry (as follows) my entire root module fails to compile a single route and yet I get no "usable" error or other indicator as to what might have happened.

GET   /assets/*file  controllers.Assets.at(path="/public", file)

即使我注释掉了根项目中的条目,也会发生编译器错误.

The compiler errors occur even if I comment out the entry in the root project.

因为我所有的子模块控制器都有一个前缀,所以我尝试了这个前缀(当然)

As all my sub modules controllers have a prefix I tried that (of course)

GET   /assets/*file  controllers.submodule.Assets.at(path="/public", file)

A俩也不管用,但至少我收到一个有用的错误,告诉我type Assets is not a member of package controllers.submodule

Alas that doesn't work either but at least I get a useful error telling me the type Assets is not a member of package controllers.submodule

有什么建议吗?

PS:是的,如果只是名称空间冲突,我也尝试过从根的路由文件中删除该条目...

PS: Yes I've also tried taking the entry out of the root's routing file in case it was just a name space collision...

推荐答案

您必须在子模块控制器包中创建一个Assets控制器:

You have to create an Assets controller in your submodule controllers package:

package controllers.submodule

class Assets extends AssetsBuilder(DefaultHttpErrorHandler)

然后在子模块的路由器文件(应将其命名为submodule.routes)中声明此控制器的路由:

Then declare a route for this controller in the router file (it should be named submodule.routes) of your submodule:

GET    /submodule/public/*file    controllers.submodule.Assets.versioned(path="/public", file: Asset)

最好在路由前面加上子模块的名称,以免在出现其他带有静态路由条目的子模块名称的情况下避免路由冲突.

It is better to prefix the route with the name of your submodule to avoid route colision in case you have other submodules name with static route entry.

另一件事:所有静态文件都托管在根模块的"lib"文件夹中:

One more thing: all your static files are hosted in the "lib" folder of your root module:

lib/submodule/css...
lib/submodule/js...

所以您必须像这样更新视图:

So you have to update your views like that:

<script type="text/javascript" src="@controllers.submodule.routes.Assets.versioned("lib/submodule/js/your-submodule-script.js")"></script>

编辑:不要忘记将其添加到根模块的路由文件(命名路由)中

don't forget to add this to your route file (named routes) of your root module

-> / submodule.routes

这篇关于Play Framework [2.4.x]如何解决子模块的路由文件中的公共资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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