问题描述
我正在使用简单的 java 和 jersey 来休息。下面是方法。来自邮递员,我正在发送 json 请求并希望将此数据检索到方法中而不声明 POJO 类。但无法检索。
{"2021-03-15": [{"10:30:00": 45},{"18:30:00": 35}]}
我想将请求 json 参数(fileType,groupId,sourceId)检索到方法 this request json parameter 中。
有人可以帮我吗?
解决方法
为什么要在另一种方法中检索请求参数或标头?
一个方法处理一个请求,就是这样,但是如果您想将部分功能隔离到单独的方法中,您可以在请求处理方法中调用另一个方法。
@Path("{entity}/markLabel")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response markLabel(ReqObject String reqBody) throws Exception {
//////do something
someOtherMethod(reqBody);
//////do something
}
class ReqObject{
String fileType;
String groupId;
String sourceId;
//getters and setters
}