在我的 playframework 应用程序中,我想做一个简单的 Post 请求。所以我在我的路线中定义了这个:POST /printName @controllers.Index.printName()就像我在scala中做的一样。然后我有以下控制器功能:public Result printName(Http.Request request) { JsonNode json = request.body().asJson(); return ok("Got name: " + json.get("name").asText());}所以现在编译器返回:类索引中的方法 printName 缺少参数;如果您想将其视为部分应用的函数,请使用 `_' 遵循此方法当我像这样在路由中添加参数时:POST /printName @controllers.Index.printName(request: Request)然后我得到了这个错误未找到:类型请求怎么会是正确的?示例来自 Playframework 页面:https ://www.playframework.com/documentation/2.7.x/JavaBodyParsers#The-default-body-parser提前致谢。
1 回答

侃侃尔雅
TA贡献1801条经验 获得超16个赞
我找到了解决方案:
控制器功能
public Result printName() {
Http.Request request = request();
JsonNode json = request.body().asJson();
return ok("Got name: " + json.get("name").asText());
}
和路线
POST /printName @controllers.Index.printName()
添加回答
举报
0/150
提交
取消