首页 > 解决方案 > 找不到 Scala Play 路由操作

问题描述

我不明白为什么这不起作用。

在此处输入图像描述

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Serve index page from public directory
GET     /                           controllers.HomeController.index
GET     /index                               controllers.FrontendController.index

# An example route (Prefix all API routes with apiPrefix defined in application.conf)
GET     /api/summary                controllers.HomeController.appSummary
POST    /api/getplt/:args                     controllers.UploadController.getPlt(args)# Serve static assets under public directory
GET     /*file                      controllers.FrontendController.assetOrDefault(file)

为什么它不能解决这个动作?我可以毫无问题地解决 /api/summary 。

标签: scalaplayframework

解决方案


首先为您的资产使用以下内容:

# Map static resources from the /public folder to the /assets URL path
 GET     /assets/*file               controllers.Assets.at(file)

然后你可以assetFinder在你的视图中使用,比如:

<script src="@assetsFinder.path("javascripts/jquery.js")" type="text/javascript"></script>

这是因为尽量避免任何相似/相同的路线,您的第一条路线和资产相关路线看起来几乎相同。

因此,要回答您的问题,要么 Play 混合了这两条路线,要么您的班级中没有index方法。HomeController


推荐阅读