[英]POST Request in Playframework Java
Hi In my playframework application I want to do a simple Post request. 您好在我的playframework应用程序中,我想执行一个简单的Post请求。
So I defined in my Route this: 所以我在我的路线中定义了:
POST /printName @controllers.Index.printName()
Same way I do it in scala. 我在Scala中也这样做。
Then I have the following controller function: 然后,我具有以下控制器功能:
public Result printName(Http.Request request) {
JsonNode json = request.body().asJson();
return ok("Got name: " + json.get("name").asText());
}
So now compiler returns: 因此,现在编译器返回:
missing arguments for method printName in class Index;
类Index中的方法printName缺少参数; follow this method with `_' if you want to treat it as a partially applied function
如果要将其视为部分应用的函数,请在此方法后加上“ _”
When I add the parameter in The route like this: 当我在路由中添加参数时,如下所示:
POST /printName @controllers.Index.printName(request: Request)
Then I got this error 然后我得到这个错误
not found: type Request
找不到:输入请求
How would it be correct? 怎么会正确呢? Example is from Playframework page: https://www.playframework.com/documentation/2.7.x/JavaBodyParsers#The-default-body-parser
示例来自Playframework页面: https ://www.playframework.com/documentation/2.7.x/JavaBodyParsers#The-default-body-parser
Thanks in advance. 提前致谢。
I found the solution: 我找到了解决方案:
controller function 控制器功能
public Result printName() {
Http.Request request = request();
JsonNode json = request.body().asJson();
return ok("Got name: " + json.get("name").asText());
}
and the route 和路线
POST /printName @controllers.Index.printName()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.