JAX-RS 发布多个对象 [英] JAX-RS Post multiple objects

查看:40
本文介绍了JAX-RS 发布多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法;

@POST
@Path("test")
@Consumes(MediaType.APPLICATION_JSON)
public void test(ObjectOne objectOne, ObjectTwo objectTwo)

现在我知道我可以以 json 格式发布单个对象,只需将其放入正文即可.但是可以做多个对象吗?如果是,怎么办?

Now I know I can post a single object in json format, just putting it into the body. But is it possible to do multiple objects? If so, how?

推荐答案

答案是.

原因很简单:这是关于您可以在方法中接收的参数.它们必须与请求相关.对?因此它们必须是标头或 cookie 或查询参数或矩阵参数或路径参数或请求正文.(只是为了讲述完整的故事,还有称为上下文的其他类型的参数).

The reason is simple: This about the parameters you can receive in a method. They must be related to the request. Right? So they must be either headers or cookies or query parameters or matrix parameters or path parameters or request body. (Just to tell the complete story there is additional types of parameters called context).

现在,当您在请求中收到 JSON 对象时,您会在请求正文中收到它.请求可能有多少个主体?一个而且只有一个.所以你只能接收一个 JSON 对象.

Now, when you receive JSON object in your request, you receive it in a request body. How many bodies the request may have? One and only one. So you can receive only one JSON object.

这篇关于JAX-RS 发布多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆