来自 HTTP 请求主体的数据如何传递到 servlet

How is data from HTTP request body passed into a servlet

我是 Java 网络编程的新手,我正在阅读以下使用 Spring 和 swagger 的代码。我不明白 jsonRequestBody 参数是如何用来自 HTTP POST 请求正文的数据填充的。我从某处读到应该使用 @RequestBody 注释来读取请求正文,就像您使用 @PathParam@QueryParam 的方式一样,但在这种情况下不使用。 Spring 是如何弄清楚如何解析 HTTP 请求正文并将其放入 jsonRequestBody 中的?

    @POST
    @Path("{transactionId}")
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces({ MediaType.APPLICATION_JSON })
    @ApiOperation(value = "Update Running balances for Journal Entries", notes = "This API calculates the running balances for office. If office ID not provided this API calculates running balances for all offices. \n" + "Mandatory Fields\n" + "officeId")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "body", value = "body", dataType = "body", dataTypeClass = JournalEntriesApiResourceSwagger.PostJournalEntriesTransactionIdRequest.class)})
    @ApiResponses({@ApiResponse(code = 200, message = "", response = JournalEntriesApiResourceSwagger.PostJournalEntriesTransactionIdResponse.class)})
    public String createReversalJournalEntry(@ApiParam(hidden = true) final String jsonRequestBody, @PathParam("transactionId") @ApiParam(value = "transactionId") final String transactionId,
            @QueryParam("command") @ApiParam(value = "command") final String commandParam) {
    //.... 
  }

我在这里找到了答案:。事实证明,只要方法被标记为@POST,方法的String参数就会自动填充请求体中的数据。