我正在使用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
希望这会有所帮助!