如何传递给控制器方法请求体?
How to pass to the controller method request body?
我正在使用 play framework 2.8.x
,我需要传递给控制器请求正文。我想做这样的事情:
public class HomeController extends Controller {
public Result test(String tokenId) {
...
return ok();
}
}
然后像这样发送请求:
我该怎么做?
您需要从 Request
对象中获取它,例如:
@BodyParser.Of(BodyParser.Json.class)
public Result index(Http.Request request) {
JsonNode json = request.body().asJson();
String tokenId = json .get("tokenId").asText();
...
return ok();
}
详情请看官方文档:https://www.playframework.com/documentation/2.8.x/JavaBodyParsers#Body-parsers
希望对您有所帮助!
我正在使用 play framework 2.8.x
,我需要传递给控制器请求正文。我想做这样的事情:
public class HomeController extends Controller {
public Result test(String tokenId) {
...
return ok();
}
}
然后像这样发送请求:
我该怎么做?
您需要从 Request
对象中获取它,例如:
@BodyParser.Of(BodyParser.Json.class)
public Result index(Http.Request request) {
JsonNode json = request.body().asJson();
String tokenId = json .get("tokenId").asText();
...
return ok();
}
详情请看官方文档:https://www.playframework.com/documentation/2.8.x/JavaBodyParsers#Body-parsers
希望对您有所帮助!