[英]How to do routing in Play framework?
I am new to Play Framework
and trying to setup a very small project in Intellij
. 我是Play Framework
新手,并尝试在Intellij
设置一个非常小的项目。 So, I followed some basic steps: 因此,我遵循了一些基本步骤:
Java
class file in Controller package. 现在,我在Controller程序包中添加了一个新的Java
类文件。 config/routes
file. 在config/routes
文件中添加路由配置。 public class TestController extends Controller {
public F.Promise<Result> createTest() {
return F.Promise.promise(() -> TestEndpoints.createTest(Json.fromJson(request().body().asJson(),
Test.class))).map((result) -> ok(Json.toJson(result)));
}
POST /Test controllers.TestController.createTest()
When I run the project I got this error: 当我运行项目时,出现以下错误:
value createTest is not a member of object controllers.TestController
Why is this happening. 为什么会这样呢? One thing I just noticed that my Controller folder has Application.scala
not Application.java
. 我刚刚注意到我的Controller文件夹具有Application.scala
而不是Application.java
一件事。 What I am doing wrong here? 我在这里做错了什么?
Play switched to using dependency injection and therefore the way to reference a function in your Controller is: 播放切换为使用依赖注入,因此在Controller中引用函数的方式是:
POST /Test @controllers.TestController.createTest() POST /测试@ controllers.TestController.createTest()
Notice the '@' 注意“ @”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.